screen - manage a virtual ‘screen’

This implements a virtual screen. This is used to support ANSI terminal emulation. The screen representation and state is implemented in this class. Most of the methods are inspired by ANSI screen control codes. The ANSI class extends this class to add parsing of ANSI escape codes.

PEXPECT LICENSE

This license is approved by the OSI and FSF as GPL-compatible.
http://opensource.org/licenses/isc-license.txt

Copyright (c) 2012, Noah Spurrier <noah@noah.org> PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class pexpect.screen.screen(r=24, c=80)[source]

This object maintains the state of a virtual text screen as a rectangluar array. This maintains a virtual cursor position and handles scrolling as characters are added. This supports most of the methods needed by an ANSI text screen. Row and column indexes are 1-based (not zero-based, like arrays).

__init__(r=24, c=80)[source]

This initializes a blank screen of the given dimensions.

__str__()[source]

This returns a printable representation of the screen. The end of each screen line is terminated by a newline.

clear_all_tabs()[source]

Clears all tabs.

clear_tab()[source]

Clears tab at the current position.

cr()[source]

This moves the cursor to the beginning (col 1) of the current row.

crlf()[source]

This advances the cursor with CRLF properties. The cursor will line wrap and the screen may scroll.

cursor_constrain()[source]

This keeps the cursor within the screen area.

cursor_force_position(r, c)[source]

Identical to Cursor Home.

cursor_restore_attrs()[source]

Restores cursor position after a Save Cursor.

cursor_save()[source]

Save current cursor position.

cursor_save_attrs()[source]

Save current cursor position.

cursor_unsave()[source]

Restores cursor position after a Save Cursor.

dump()[source]

This returns a copy of the screen as a string. This is similar to __str__ except that lines are not terminated with line feeds.

erase_down()[source]

Erases the screen from the current line down to the bottom of the screen.

erase_end_of_line()[source]

Erases from the current cursor position to the end of the current line.

erase_line()[source]

Erases the entire current line.

erase_screen()[source]

Erases the screen with the background color.

erase_start_of_line()[source]

Erases from the current cursor position to the start of the current line.

erase_up()[source]

Erases the screen from the current line up to the top of the screen.

get_region(rs, cs, re, ce)[source]

This returns a list of lines representing the region.

insert_abs(r, c, ch)[source]

This inserts a character at (r,c). Everything under and to the right is shifted right one character. The last character of the line is lost.

lf()[source]

This moves the cursor down with scrolling.

newline()[source]

This is an alias for crlf().

pretty()[source]

This returns a copy of the screen as a string with an ASCII text box around the screen border. This is similar to __str__ except that it adds a box.

put(ch)[source]

This puts a characters at the current cursor position.

put_abs(r, c, ch)[source]

Screen array starts at 1 index.

scroll_constrain()[source]

This keeps the scroll region within the screen region.

scroll_down()[source]

Scroll display down one line.

scroll_screen()[source]

Enable scrolling for entire display.

scroll_screen_rows(rs, re)[source]

Enable scrolling from row {start} to row {end}.

scroll_up()[source]

Scroll display up one line.

set_tab()[source]

Sets a tab at the current position.