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, encoding='latin-1', encoding_errors='replace')[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).
Characters are represented internally using unicode. Methods that accept input characters, when passed ‘bytes’ (which in Python 2 is equivalent to ‘str’), convert them from the encoding specified in the ‘encoding’ parameter to the constructor. Methods that return screen contents return unicode strings, with the exception of __str__() under Python 2. Passing
encoding=None
limits the API to only accept unicode input, so passing bytes in will raiseTypeError
.-
__init__
(r=24, c=80, encoding='latin-1', encoding_errors='replace')[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.
-
crlf
()[source]¶ This advances the cursor with CRLF properties. The cursor will line wrap and the screen may scroll.
-
dump
()[source]¶ This returns a copy of the screen as a unicode string. This is similar to __str__/__unicode__ except that lines are not terminated with line feeds.
-
erase_end_of_line
()[source]¶ Erases from the current cursor position to the end of the current line.
-
erase_start_of_line
()[source]¶ Erases from the current cursor position to the start of the current line.
-
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.
-