It was inevitable, after I started noodling around with terminal colors in ConEmu, that I’d waste an afternoon cooking up a way to color my Maya terminal sessions automatically.
The actual code is up on GitHub (under the usual MIT Open License - enjoy!).
As implemented, its a module you can activate simply by importing
conemu. Ordinarily I don’t like modules that ‘do things’ on import, but this one is such a special case that it seems justifiable. Importing the module will replace
sys.display_hook with ConEmu-specific classes that do a little color formatting to make it easier to work in
mayapy. If for some reason you want to disable it, calling
conemu.unset_terminal() will restore the default terminal.
Here are the main features:
This helps de-emphasize the prompt, which is the least interesting but item on screen, and to emphasize command results or printouts
Since all Maya objects returned by commands are printed as unicode string (like
u'pCube1', the terminal highlights unicode strings in a different color to make it easy to pick out Maya objects in return values. The annoying little
u is also suppressed.
Code objects (classes, functions and so on) are highlighted separately
Lines beginning with a
# or a
/ will be highlighted differently, allowing you separate out ordinary command results from warnings and infos. In this version I have not isolated the path used by
cmds.warning, which makes this less useful. Does anybody out there know which pipe that uses? It appears to bypass
sys.stdout.write() and sys.stderr.write()
If the result of a command is anything other than a string, it will be run through
prettyprint so that it will be formatted in a slightly more legible manner. This is particularly handy for commands like
listAttr which produce a lot of results:
pprint will arrange these vertically if they result would otherwise be wider than 80 characters.
The module contains some helper classes if you want to make your own display more elaborate, or to mess with it interactively during a console session.
Terminal class makes it less cumbersome to control the display. The main use is to color or highlight text. The 16 terminal colors are available as
Terminal.color, and you can highlight a piece of text like so:
print "this is " + Terminal.color("colored text")
The background colors are
terminal.bg and work the same way:
print Terminal.bg("backgound text")
Terminal also has a helper for setting, coloring, and unsetting prompt strings.
Conemu class includes some limited access to the more elaborate functions offered by ConEmu (The methods in
Terminal might work in other ANSI terminals – I haven’t tried ! – but the ConEmu ones specific to ConEmu). The key methods are:
Pops up a GUI confirm dialog with ‘message’ in it.
Sets the name of the current ConEmu tab to ‘message’.
Sets the name of the current ConEmu window to ‘message’.
active is True, draw a progress indicator in the window task bar at
progress percent. For example
ConEmu.progress(True, 50) overlays a 50% progress bar on the ConEmu task bar icon. If
active is false, the progress bar is hidden. This can be handy for long running batch items