cmd2.terminal_utils
cmd2.terminal_utils
Support for terminal control escape sequences.
These are used for things like setting the window title and asynchronous alerts.
Cursor
Create ANSI sequences to alter the cursor position.
UP
staticmethod
DOWN
staticmethod
FORWARD
staticmethod
BACK
staticmethod
set_title_str
Generate a string that, when printed, sets a terminal's window title.
| PARAMETER | DESCRIPTION |
|---|---|
title
|
new title for the window
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the set title string |
clear_screen_str
Generate a string that, when printed, clears a terminal screen based on value of clear_type.
| PARAMETER | DESCRIPTION |
|---|---|
clear_type
|
integer which specifies how to clear the screen (Defaults to 2) Possible values: 0 - clear from cursor to end of screen 1 - clear from cursor to beginning of the screen 2 - clear entire screen 3 - clear entire screen and delete all lines saved in the scrollback buffer
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the clear screen string |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
if clear_type is not a valid value |
Source code in cmd2/terminal_utils.py
clear_line_str
Generate a string that, when printed, clears a line based on value of clear_type.
| PARAMETER | DESCRIPTION |
|---|---|
clear_type
|
integer which specifies how to clear the line (Defaults to 2) Possible values: 0 - clear from cursor to the end of the line 1 - clear from cursor to beginning of the line 2 - clear entire line
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the clear line string |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
if clear_type is not a valid value |
Source code in cmd2/terminal_utils.py
async_alert_str
Calculate the desired string, including ANSI escape codes, for displaying an asynchronous alert message.
| PARAMETER | DESCRIPTION |
|---|---|
terminal_columns
|
terminal width (number of columns)
TYPE:
|
prompt
|
current onscreen prompt
TYPE:
|
line
|
current contents of the Readline line buffer
TYPE:
|
cursor_offset
|
the offset of the current cursor position within line
TYPE:
|
alert_msg
|
the message to display to the user
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
the correct string so that the alert message appears to the user to be printed above the current line. |