Note: This module is inlined from pycrash.

cly.console

Console/terminal interaction classes and functions.

This module provides a simple formatting syntax for basic terminal visual control sequences. The syntax is a carat ^ followed by a single character.

Valid colour escape sequences are:

^N:Reset all formatting.
^B:Toggle bold.
^U:Toggle underline.
^0:Set black foreground.
^1:Set red foreground.
^2:Set green foreground.
^3:Set brown foreground.
^4:Set blue foreground.
^5:Set magenta foreground.
^6:Set cyan foreground.
^7:Set white foreground.

mono_cwrite(io, text)

(Not documented)

class _Codec()

(Not documented)

__init__(self, **args, *kwargs)

(Not documented)

decode(self, input, errors='strict')

(Not documented)

encode(self, input, errors='strict')

(Not documented)

reset(self)

(Not documented)

class _CodecStreamWriter()

(Not documented)

__init__(self, stream, errors='strict')

(Not documented)

write(self, object)

(Not documented)

writelines(self, lines)

(Not documented)

class _CodecStreamReader()

(Not documented)

__init__(self, stream, errors='strict')

(Not documented)

read(self, size=1, chars=1)

(Not documented)

readline(self, size=None, keepends=True)

(Not documented)

readlines(self, sizehint=None, keepends=True)

(Not documented)

seek(self, offset, whence=0)

(Not documented)

register_codec()

Register the 'cly' codec with Python.

The formatting syntax can then be used like any other codec:

>>> register_codec()
>>> '^Bbold^B'.decode('cly')
'\x1b[1mbold\x1b[22m'
>>> '\x1b[1mbold\x1b[22m'.encode('cly')
'^Bbold^B'

cprint(*args)

Emulate the print builtin, with terminal shortcuts.

cprintstrip(*args)

As with cprint, but strip colour codes.

clen(arg)

Return the length of arg after colour codes are stripped.

cerror(*args)

Print a message in red to stderr.

cfatal(*args)

Print a message in red to stderr then exit with status -1.

cwarning(*args)

Print a yellow warning message to stderr.

cinfo(*args)

Print a green notice.

termwidth()

Guess the current terminal width.

Returns -1 if the terminal width can not be determined.

termheight()

Guess the current terminal height.

Returns -1 if the terminal height can not be determined.

csplice(text, start=0, end=1)

Splice a colour encoded string.

cwraptext(rtext, width=None, subsequent_indent='')

Wrap multi-line text to width (defaults to :func:`termwidth`)

System Message: ERROR/3 (<string>, line 1); backlink

Unknown interpreted text role "func".

wraptoterm(text, **kwargs)

Wrap the given text to the current terminal width

rjustify(text, width=None)

Right justify the given text.

cjustify(text, width=None)

Centre the given text.

print_table(header, table, sep=u' ', indent=u'', expand_to_fit=True, header_format='^B^U', row_format=^6^B^6, min_widths=None, term_width=None)

Print a list of lists as a table, so that columns line up nicely.

param header:List of column headings. Will be printed as the first row.
param table:List of lists for the table body.
param sep:The column separator.
param indent:Table indentation as a string.
param header_format:
 Formatting to use for header.
param row_format:
 A tuple specifying cycling formatting colours to use for each row.
param expand_to_fit:
 If a boolean, signifies whether print_table should expand the table to the width of the terminal or compact it as much as possible. If an integer, specifies the width to expand to.
param min_widths:
 Columns will be guaranteed to be at least the width of each element in this list. May also be a dictionary of column indices to widths.
param term_width:
 Override terminal width detection.
returns:List of strings, one per line.

Note: In addition to the normal formatting codes supported by :func:`cprint`, :func:`print_table` supports the ^R formatting code, which corresponds to the colour formatting of the current table row.

System Message: ERROR/3 (<string>, line 21); backlink

Unknown interpreted text role "func".

System Message: ERROR/3 (<string>, line 21); backlink

Unknown interpreted text role "func".