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.
Prints string in to stdout using colored font.
See L{set_color} for more details about colors.
Parameters: |
|
---|
Set the console color.
>>> set_color(Color.red, Color.blue)
>>> set_color('red', 'blue')
>>> set_color() # returns back to normal
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. |
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.
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.
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.
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.
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.
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.
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.
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 |
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.