I recommend that you create a single method print_color_string that takes a string and the color to print. It's not very flexible for the code that is using your library. This sounds like you are repeating yourself a lot. Judging by the name of the method your presented and the context of the code, you have created a separate method for each color. "All modern terminal emulators use ANSI escape codes to show colours Therefore, you can remove the checking of the operating system. Therefore, it doesn't really matter what OS it is: if it's an ANSI terminal, you can use ANSI colored output. ANSI color printing is only going to work on terminals that are ANSI compatible. Is this an incredibly klutzy/dumb implementation? From what I've read, so far, cross platform capability for ANSI color printing has only gotten shakier, not simpler.įirst off, "cross platform capability for ANSI color printing" doesn't quite make sense (if I understand correctly). If colorama doesn't work on a Windows system for some reason I can change the global boolean coloursOn. HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8. # change the global variable for colours. # we'll try the Colorama option but if it fails we can """print some text with cyan foreground""" The PRN class that handles the print calls: class cyan(p_str): Move to fixed width (80 column canvas) to build stability. These colors are red, orange, yellow, green, blue, purple, gray, black, white, and combinations of black, white, and/or yellow. Right click of color pallette sets background color. ANSI color codes for safety signs are described in ANSI Z535.1-2011. Enter/click places copied/cut block, escape cancels copy/cut. Prints are called, for example, via PRN.cyan("some string").įor this to work I import colorama: from colorama import init, Fore, Back, Style Ctrl-x cuts, ctrl-c copies, del deletes, ctrl-f f, to fill foreground, ctrl-f b to fill background (BUG: Fills with foreground color). They called the class bcolors but I wanted to reduce clutter so I renamed it.īut the main class is what I've written that determines the os before printing. The clrs code I refer to is apparently from blender build scripts, I discovered it on this SO post. I am trying to write for both NT and POSIX (my two usual platforms) and have come up with the code below.
0 Comments
Leave a Reply. |