rich.control

class rich.control.Control(*codes)[source]

A renderable that inserts a control code (non printable but may move cursor).

Parameters:

*codes (str) – Positional arguments are either a ControlType enum or a tuple of ControlType and an integer parameter

classmethod alt_screen(enable)[source]

Enable or disable alt screen.

Parameters:

enable (bool)

Return type:

Control

classmethod bell()[source]

Ring the ‘bell’.

Return type:

Control

classmethod clear()[source]

Clear the screen.

Return type:

Control

classmethod home()[source]

Move cursor to ‘home’ position.

Return type:

Control

classmethod move(x=0, y=0)[source]

Move cursor relative to current position.

Parameters:
  • x (int) – X offset.

  • y (int) – Y offset.

Returns:

Control object.

Return type:

~Control

classmethod move_to(x, y)[source]

Move cursor to absolute position.

Parameters:
  • x (int) – x offset (column)

  • y (int) – y offset (row)

Returns:

Control object.

Return type:

~Control

classmethod move_to_column(x, y=0)[source]

Move to the given column, optionally add offset to row.

Returns:

absolute x (column) y (int): optional y offset (row)

Return type:

x (int)

Returns:

Control object.

Return type:

~Control

Parameters:
classmethod show_cursor(show)[source]

Show or hide the cursor.

Parameters:

show (bool)

Return type:

Control

classmethod title(title)[source]

Set the terminal window title

Parameters:

title (str) – The new terminal window title

Return type:

Control

rich.control.escape_control_codes(text, _translate_table={7: '\\a', 8: '\\b', 11: '\\v', 12: '\\f', 13: '\\r'})[source]

Replace control codes with their “escaped” equivalent in the given text. (e.g. “” becomes “b”)

Parameters:
  • text (str) – A string possibly containing control codes.

  • _translate_table (Dict[int, str])

Returns:

String with control codes replaced with their escaped version.

Return type:

str

rich.control.strip_control_codes(text, _translate_table={7: None, 8: None, 11: None, 12: None, 13: None})[source]

Remove control codes from text.

Parameters:
  • text (str) – A string possibly contain control codes.

  • _translate_table (Dict[int, None])

Returns:

String with control codes removed.

Return type:

str