Implements various utility methods providing a console UI support
toolkit, most notably an epytext-to-console text renderer using ANSI
escape sequences. It uses the Borg pattern to share state between
instances.
|
__init__(self,
stdin=sys.stdin,
stdout=sys.stdin)
Initializes a Console instance. |
|
|
|
escape(self,
sequence,
reply_terminator=None)
Sends an escape sequence to the console, and reads the reply
terminated by reply_terminator. |
|
|
|
get_width(self)
Returns the console width, or maximum width if we are not a terminal
device. |
|
|
|
get_cursor_xy(self)
Get the current text cursor x, y coordinates. |
|
|
|
|
|
raw_write(self,
text)
Raw console printing function. |
|
|
|
display(self,
text,
no_lf=False)
Display a text with a default style. |
|
|
|
epy_write(self,
text)
Renders and print and epytext-formatted text on the console. |
|
|
|
indent(self,
text,
margin=2)
Indents text by margin space. |
|
|
|
dedent(self,
text)
A convenience function to easily write multiline text blocks that
will be later assembled in to a unique epytext string. |
|
|
|
render_text(self,
text,
fgcolor=None,
bgcolor=None,
styles=None,
open_end=False,
todefault=False)
Renders some text with ANSI console colors and attributes. |
|
|
str
|
wordwrap(self,
text,
indent=0,
startindex=0,
splitchars='
' )
Word-wrap the given string. |
|
|
string
|
render_domtree(self,
tree,
indent=0,
seclevel=0)
Convert a DOM document encoding epytext to an 8-bits ascii string
with ANSI formating for simpler styles. |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
|
_max_width = 132
|
|
_escape = ' \x1b[ '
|
|
_ansi_format = ' \x1b[%dm%s '
|
|
_ansi_reset = ' \x1b[0m '
|
|
_re_ansi_seq = re.compile(r'( \x1b\[..? m) ')
|
|
_ansi_styles = { ' blink ' : 5, ' bold ' : 1, ' concealed ' : 8, ' revers ...
|
|
colors = [ ' black ' , ' red ' , ' green ' , ' yellow ' , ' blue ' , ' magenta ' ...
|
|
_ansi_fgcolors = { ' black ' : 30, ' blue ' : 34, ' cyan ' : 36, ' green ' ...
|
|
_ansi_bgcolors = { ' black ' : 40, ' blue ' : 44, ' cyan ' : 46, ' green ' ...
|
|
__borg_state = { }
|