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.stdout
, sys.stdin
, and 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:
Colored prompts and printouts
This helps de-emphasize the prompt, which is the least interesting but item on screen, and to emphasize command results or 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 u
is also suppressed.Code objects highlighted
Code objects (classes, functions and so on) are highlighted separately
Comment colors
#
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() Automatic prettyprint
prettyprint
so that it will be formatted in a slightly more legible manner. This is particularly handy for commands like ls
or 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. Utilities
The Terminal: screen formatting
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[0]
through Terminal.color[15]
, and you can highlight a piece of text like so:print "this is " + Terminal.color[10]("colored text")
Terminal.bg[0]
through terminal.bg[5]
and work the same way:print Terminal.bg[2]("backgound text")
Terminal
also has a helper for setting, coloring, and unsetting prompt strings.The Conemu: console control
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:ConEmu.alert(message)
- Pops up a GUI confirm dialog with ‘message’ in it.
ConEmu.set_tab(message)
- Sets the name of the current ConEmu tab to ‘message’.
ConEmu.set_title(message)
- Sets the name of the current ConEmu window to ‘message’.
ConEmu.progress(active, progress)
- if
active
is True, draw a progress indicator in the window task bar atprogress
percent. For exampleConEmu.progress(True, 50)
overlays a 50% progress bar on the ConEmu task bar icon. Ifactive
is false, the progress bar is hidden. This can be handy for long running batch items
No comments:
Post a Comment