tea.console

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.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:
  • color (str or list[str]) – If color is a string than this is a color in which the text will appear. If color is a list of strings than all desired colors will be used as a mask (this is used when you wan to set foreground and background color).
  • text (str) – Text that needs to be printed.
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.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.

@type text: string @param text: Text to wrap. @type width: integer @param width: Maximum number of characters per line. @rtype: string @return: Centered text.

tea.console.format.format_page(text)

Formats the text for output adding ASCII frame around the text.

@type text: string @param text: Text that needs to be formatted. @rtype: string @return: Formatted string.

tea.console.format.hbar(width)

Returns ASCII HBar +—+ with the specified width.

@type width: integer @param width: Width of the central part of the bar. @rtype: string @return: ASCII HBar.

tea.console.format.print_page(text)

Formats the text and prints it on stdout.

Text is formated 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.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.

@type text: string @param text: Text to wrap and align. @type width: integer @param width: Maximum number of characters per line. @type indent: integer @param indent: Indentation of the first line. @type subsequent: integer or None @param subsequent: Indentation of all other lines, if it is None, then the

indentation will be same as for the first line.
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 | +————-+——–+

@type text: string @param text: Text that needs to be formatted. @rtype: string @return: Formatted string.

tea.console.format.wrap_text(text, width=80)

Wraps text lines to maximum width characters.

Wrapped text is aligned against the left text border.

@type text: string @param text: Text to wrap. @type width: integer @param width: Maximum number of characters per line. @rtype: string @return: Wrapped 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.

Project Versions

Previous topic

tea.commander

Next topic

tea.cron

This Page