numworks / epsilon

Modern graphing calculator operating system.
https://www.numworks.com/resources/engineering/software/
1.75k stars 464 forks source link

Colored Output (from colorama) in Python shell or from programs printing to the shell #1948

Open mobluse opened 2 years ago

mobluse commented 2 years ago

Problem you'd like to fix

To just have black on white in the shell is boring. It would be nice and educational if you could set some colors and styles of output in the shell.

The Python3 module colorama has these colors and styles, but DIM is the same as NORMAL in some systems: Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET Style: DIM, NORMAL, BRIGHT, RESET_ALL

One should also be able to use the corresponding ANSI/VT100/xterm escape codes for these colors and styles. This should work for both the large and small font.

Some shells in IDE:s for computers handles this, e.g. Thonny and Mu.

Describe the solution you'd like

These examples should work as in Thonny, Mu, and Python3 in e.g. LXTerminal with colorama installed:

from colorama import Fore, Back, Style
print(Fore.RED + "Red" + Style.RESET_ALL)
print(Style.BRIGHT + Fore.YELLOW + Back.CYAN + "Bright yellow text on cyan background" + Style.RESET_ALL)
print("\033[31m" + "Red" + "\033[m")
print("\033[1;33;46m" + "Bright yellow text on cyan background" + "\033[m")

Describe alternatives you've considered

I would bring up screen and line clearing, and cursor positioning in other issues, because Thonny and Mu doesn't support these in my versions now.

Additional context

In general I think the shell should work more like Pyhon3 in xterm, see also issue https://github.com/numworks/epsilon/issues/1892.

DarkBrines commented 1 year ago

Nice idea

mobluse commented 1 week ago

I think colorama doesn't have to be supported, the important thing is to support some of the escape codes that colorama supports. I.e. the above mentioned for color and some for positioning on a line, and clear line and screen.

Thonny 4.1.4 supports:

ESC [ n C       # move cursor n characters forward
ESC [ n D       # move cursor n characters backward

Mu 1.0.3 supports:

# clear the screen
ESC [ mode J    # clear the screen (Mu seems to always do ESC [ 2 J even if 0 or 1 is used.) 

# clear the line
ESC [ mode K    # clear the line (Mu tries to use the different modes (0, 1, 2) correctly.)