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_hookwith 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:
Colored prompts and printouts
Unicode objects highlighted
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
uis also suppressed.
Code objects highlighted
Code objects (classes, functions and so on) are highlighted separately
/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
prettyprintso that it will be formatted in a slightly more legible manner. This is particularly handy for commands like
listAttrwhich produce a lot of results:
pprintwill 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. Utilities
The Terminal: screen formatting
Terminalclass 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")
terminal.bgand work the same way:
print Terminal.bg("backgound text")
Terminalalso has a helper for setting, coloring, and unsetting prompt strings.
The Conemu: console control
Conemuclass includes some limited access to the more elaborate functions offered by ConEmu (The methods in
Terminalmight 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’.
activeis True, draw a progress indicator in the window task bar at
progresspercent. For example
ConEmu.progress(True, 50)overlays a 50% progress bar on the ConEmu task bar icon. If
activeis false, the progress bar is hidden. This can be handy for long running batch items