class TerminalController:
A class that can be used to portably generate formatted output to a terminal.
TerminalController defines a set of instance variables whose values are initialized to the control sequence necessary to perform a given action. These can be simply included in normal output to the terminal:
>>> term = TerminalController() >>> print('This is '+term.GREEN+'green'+term.NORMAL) This is green
Alternatively, the render() method can used, which replaces ${action} with the string required to perform action:
>>> term = TerminalController() >>> print(term.render('This is ${GREEN}green${NORMAL}')) This is green
If the terminal doesn't support a given action, then the value of the corresponding instance variable will be set to ''. As a result, the above code will still work on terminals that do not support color, except that their output will not be colored. Also, this means that you can test whether the terminal supports a given action by simply testing the truth value of the corresponding instance variable:
>>> term = TerminalController() >>> if term.CLEAR_SCREEN: ... print 'This terminal supports clearning the screen.' ...
Finally, if the width and height of the terminal are known, then they will be stored in the COLS and LINES attributes.
__init__
Create a TerminalController and initialize its attributes with appropriate values for the current terminal. term_stream is the stream that will be used for terminal output; if this stream is not a tty, then the terminal is assumed to be a dumb terminal (i...
render
Replace each $-substitutions in the given template string with the corresponding terminal control string (if it's defined) or '' (if it's not).
BG_BLACK
Undocumented
BG_BLUE
Undocumented
BG_CYAN
Undocumented
BG_GREEN
Undocumented
BG_MAGENTA
Undocumented
BG_RED
Undocumented
BG_WHITE
Undocumented
BG_YELLOW
Undocumented
BLACK
Undocumented
BLINK
Undocumented
BLUE
Undocumented
BOL
Undocumented
BOLD
Undocumented
CLEAR_BOL
Undocumented
CLEAR_EOL
Undocumented
CLEAR_EOS
Undocumented
CLEAR_SCREEN
Undocumented
CYAN
Undocumented
DIM
Undocumented
DOWN
Undocumented
GREEN
Undocumented
HIDE_CURSOR
Undocumented
LEFT
Undocumented
MAGENTA
Undocumented
NORMAL
Undocumented
RED
Undocumented
REVERSE
Undocumented
RIGHT
Undocumented
SHOW_CURSOR
Undocumented
UP
Undocumented
WHITE
Undocumented
YELLOW
Undocumented
COLS
Undocumented
LINES
Undocumented
_tigetstr
Rewrites string capabilities to remove "delays" which are not required for modern terminals
_tparm
Undocumented
_render_sub
Helper function for render
_ANSICOLORS
Undocumented
_COLORS
Undocumented
_STRING_CAPABILITIES
Undocumented
Create a TerminalController and initialize its attributes with appropriate values for the current terminal. term_stream is the stream that will be used for terminal output; if this stream is not a tty, then the terminal is assumed to be a dumb terminal (i.e., have no capabilities).
Replace each $-substitutions in the given template string with the corresponding terminal control string (if it's defined) or '' (if it's not).
Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
''Undocumented
Undocumented
Rewrites string capabilities to remove "delays" which are not required for modern terminals
Undocumented
Undocumented
"""BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE""".split()Undocumented
"""BLACK BLUE GREEN CYAN RED MAGENTA YELLOW WHITE""".split()Undocumented
"""
BOL=cr UP=cuu1 DOWN=cud1 LEFT=cub1 RIGHT=cuf1
CLEAR_SCREEN=clear CLEAR_EOL=el CLEAR_BOL=el1 CLEAR_EOS=ed BOLD=bold
BLINK=blink DIM=dim REVERSE=rev UNDERLINE=smul NORMAL=sgr0
HIDE_CURSOR=cinvis SHOW_CURSOR=cnorm""".split()