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.stdout,
stderr=sys.stderr)
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,
output=sys.stdout)
Raw console printing function. |
|
|
|
display(self,
text,
no_lf=False,
error=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 = '\033['
|
|
_ansi_format = _escape+ '%dm%s'
|
|
_ansi_reset = _escape+ '0m'
|
|
_re_ansi_seq = re.compile('(\033\[..?m)')
|
|
_ansi_styles = {'bold': 1, 'underline': 4, 'blink': 5, 'revers...
|
|
colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta'...
|
|
_ansi_fgcolors = dict(zip(colors, range(30, 38)))
|
|
_ansi_bgcolors = dict(zip(colors, range(40, 48)))
|
|
__borg_state = {}
|