tea.console
Module¶
-
tea.console.
clear_screen
(numlines=100)¶ Clear the console.
Parameters: numlines (int) – This is an optional argument used only as a fall-back if the operating system console doesn’t have clear screen function. Return type: None
-
tea.console.
getch
()¶ Cross-platform getch() function.
Same as the getch function from msvcrt library, but works on all platforms. :rtype: str :return: One character got from standard input.
-
tea.console.color.
set_color
(fg='normal', bg='normal', fg_dark=False, bg_dark=False, underlined=False)¶ Set the console color.
>>> set_color(Color.red, Color.blue) >>> set_color('red', 'blue') >>> set_color() # returns back to normal
-
tea.console.color.
strip_colors
(text)¶ Helper function used to strip out the color tags so other function can determine the real text line lengths.
Parameters: text (str) – Text to strip color tags from Return type: str
Returns: Stripped text.
-
tea.console.color.
cprint
(text, fg='normal', bg='normal', fg_dark=False, bg_dark=False, underlined=False, parse=False)¶ Prints string in to stdout using colored font.
See L{set_color} for more details about colors.
Parameters:
-
tea.console.color.
colorize_output
(output, colors, indent=0)¶ Prints output to console using provided color mappings.
Color mapping is dict with regular expressions as key and tuple of two as values. Key is used to match if line should be colorized and tuple contains color to be used and boolean value that indicates if dark foreground is used. For example:
>>> CLS = { >>> re.compile(r'^(--- .*)$'): (Color.red, False) >>> }
will colorize lines that start with ‘—’ to red.
If different parts of line needs to be in different color then dict must be supplied in colors with keys that are named group from regular expression and values that are tuples of color and boolean that indicates if dark foreground is used. For example:
>>> CLS = { >>> re.compile(r'^(?P<key>user:\s+)(?P<user>.*)$'): { >>> 'key': (Color.yellow, True), >>> 'user': (Color.cyan, False) >>> } >>> }
will colorize line ‘user: Some user’ so that ‘user:’ part is yellow with dark foreground and ‘Some user’ part is cyan without dark foreground.
-
tea.console.format.
format_page
(text)¶ Formats the text for output adding ASCII frame around the text.
Parameters: text (str) – Text that needs to be formatted. Return type: string Returns: Formatted string.
-
tea.console.format.
table
(text)¶ Formats the text as a table
Text in format:
first | second row 2 col 1 | 4
Will be formatted as:
+-------------+--------+ | first | second | +-------------+--------+ | row 2 col 1 | 4 | +-------------+--------+
Parameters: text (str) – Text that needs to be formatted. Return type: str Returns: Formatted string.
-
tea.console.format.
hbar
(width)¶ Returns ASCII HBar
+---+
with the specified width.Parameters: width (int) – Width of the central part of the bar. Return type: str Returns: ASCII HBar.
-
tea.console.format.
print_page
(text)¶ Formats the text and prints it on stdout.
Text is formatted by adding a ASCII frame around it and coloring the text. Colors can be added to text using color tags, for example:
My [FG_BLUE]blue[NORMAL] text. My [BG_BLUE]blue background[NORMAL] text.
-
tea.console.format.
wrap_text
(text, width=80)¶ Wraps text lines to maximum width characters.
Wrapped text is aligned against the left text border.
Parameters: Return type: Returns: Wrapped text.
-
tea.console.format.
rjust_text
(text, width=80, indent=0, subsequent=None)¶ Same as L{wrap_text} with the difference that the text is aligned against the right text border.
Parameters:
-
tea.console.format.
center_text
(text, width=80)¶ Center all lines of the text.
It is assumed that all lines width is smaller then B{width}, because the line width will not be checked.
Parameters: Return type: Returns: Centered text.
-
tea.console.utils.
clear_screen
(numlines=100)¶ Clear the console.
Parameters: numlines (int) – This is an optional argument used only as a fall-back if the operating system console doesn’t have clear screen function. Return type: None
-
tea.console.utils.
getch
()¶ Cross-platform getch() function.
Same as the getch function from msvcrt library, but works on all platforms. :rtype: str :return: One character got from standard input.