summaryrefslogtreecommitdiff
path: root/pexpect/screen.py
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2013-09-25 15:44:36 -0700
committerThomas Kluyver <takowl@gmail.com>2013-09-25 15:44:36 -0700
commitf7832fe55f3406148bc9f22ea133ff0032db7f91 (patch)
tree8d333fdfac8853f14fd5eebfda68f56822a5062e /pexpect/screen.py
parent137f605dd0f25511e83e1bfb455676e2498fe7a2 (diff)
downloadpexpect-git-f7832fe55f3406148bc9f22ea133ff0032db7f91.tar.gz
Document screen and ANSI
Diffstat (limited to 'pexpect/screen.py')
-rw-r--r--pexpect/screen.py40
1 files changed, 4 insertions, 36 deletions
diff --git a/pexpect/screen.py b/pexpect/screen.py
index 655ab6f..61d3b97 100644
--- a/pexpect/screen.py
+++ b/pexpect/screen.py
@@ -1,7 +1,8 @@
'''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.
+Most of the methods are inspired by ANSI screen control codes. The
+:class:`~pexpect.ANSI.ANSI` class extends this class to add parsing of ANSI
+escape codes.
PEXPECT LICENSE
@@ -54,7 +55,6 @@ def constrain (n, min, max):
return n
class screen:
-
'''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
@@ -62,8 +62,7 @@ class screen:
like arrays). '''
def __init__ (self, r=24,c=80):
-
- '''This initializes a blank scree of the given dimentions.'''
+ '''This initializes a blank screen of the given dimensions.'''
self.rows = r
self.cols = c
@@ -76,21 +75,18 @@ class screen:
self.w = [ [SPACE] * self.cols for c in range(self.rows)]
def __str__ (self):
-
'''This returns a printable representation of the screen. The end of
each screen line is terminated by a newline. '''
return '\n'.join ([ ''.join(c) for c in self.w ])
def dump (self):
-
'''This returns a copy of the screen as a string. This is similar to
__str__ except that lines are not terminated with line feeds. '''
return ''.join ([ ''.join(c) for c in self.w ])
def pretty (self):
-
'''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. '''
@@ -117,14 +113,12 @@ class screen:
self.put_abs (r,c,ch)
def cr (self):
-
'''This moves the cursor to the beginning (col 1) of the current row.
'''
self.cursor_home (self.cur_r, 1)
def lf (self):
-
'''This moves the cursor down with scrolling.
'''
@@ -135,7 +129,6 @@ class screen:
self.erase_line()
def crlf (self):
-
'''This advances the cursor with CRLF properties.
The cursor will line wrap and the screen may scroll.
'''
@@ -144,14 +137,12 @@ class screen:
self.lf ()
def newline (self):
-
'''This is an alias for crlf().
'''
self.crlf()
def put_abs (self, r, c, ch):
-
'''Screen array starts at 1 index.'''
r = constrain (r, 1, self.rows)
@@ -160,14 +151,12 @@ class screen:
self.w[r-1][c-1] = ch
def put (self, ch):
-
'''This puts a characters at the current cursor position.
'''
self.put_abs (self.cur_r, self.cur_c, ch)
def insert_abs (self, r, c, ch):
-
'''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.
@@ -194,7 +183,6 @@ class screen:
self.get_abs (self.cur_r, self.cur_c)
def get_region (self, rs,cs, re,ce):
-
'''This returns a list of lines representing the region.
'''
@@ -216,7 +204,6 @@ class screen:
return sc
def cursor_constrain (self):
-
'''This keeps the cursor within the screen area.
'''
@@ -257,38 +244,32 @@ class screen:
self.scroll_up()
def cursor_force_position (self, r, c): # <ESC>[{ROW};{COLUMN}f
-
'''Identical to Cursor Home.'''
self.cursor_home (r, c)
def cursor_save (self): # <ESC>[s
-
'''Save current cursor position.'''
self.cursor_save_attrs()
def cursor_unsave (self): # <ESC>[u
-
'''Restores cursor position after a Save Cursor.'''
self.cursor_restore_attrs()
def cursor_save_attrs (self): # <ESC>7
-
'''Save current cursor position.'''
self.cur_saved_r = self.cur_r
self.cur_saved_c = self.cur_c
def cursor_restore_attrs (self): # <ESC>8
-
'''Restores cursor position after a Save Cursor.'''
self.cursor_home (self.cur_saved_r, self.cur_saved_c)
def scroll_constrain (self):
-
'''This keeps the scroll region within the screen region.'''
if self.scroll_row_start <= 0:
@@ -297,14 +278,12 @@ class screen:
self.scroll_row_end = self.rows
def scroll_screen (self): # <ESC>[r
-
'''Enable scrolling for entire display.'''
self.scroll_row_start = 1
self.scroll_row_end = self.rows
def scroll_screen_rows (self, rs, re): # <ESC>[{start};{end}r
-
'''Enable scrolling from row {start} to row {end}.'''
self.scroll_row_start = rs
@@ -312,7 +291,6 @@ class screen:
self.scroll_constrain()
def scroll_down (self): # <ESC>D
-
'''Scroll display down one line.'''
# Screen is indexed from 1, but arrays are indexed from 0.
@@ -321,7 +299,6 @@ class screen:
self.w[s+1:e+1] = copy.deepcopy(self.w[s:e])
def scroll_up (self): # <ESC>M
-
'''Scroll display up one line.'''
# Screen is indexed from 1, but arrays are indexed from 0.
@@ -330,27 +307,23 @@ class screen:
self.w[s:e] = copy.deepcopy(self.w[s+1:e+1])
def erase_end_of_line (self): # <ESC>[0K -or- <ESC>[K
-
'''Erases from the current cursor position to the end of the current
line.'''
self.fill_region (self.cur_r, self.cur_c, self.cur_r, self.cols)
def erase_start_of_line (self): # <ESC>[1K
-
'''Erases from the current cursor position to the start of the current
line.'''
self.fill_region (self.cur_r, 1, self.cur_r, self.cur_c)
def erase_line (self): # <ESC>[2K
-
'''Erases the entire current line.'''
self.fill_region (self.cur_r, 1, self.cur_r, self.cols)
def erase_down (self): # <ESC>[0J -or- <ESC>[J
-
'''Erases the screen from the current line down to the bottom of the
screen.'''
@@ -358,7 +331,6 @@ class screen:
self.fill_region (self.cur_r + 1, 1, self.rows, self.cols)
def erase_up (self): # <ESC>[1J
-
'''Erases the screen from the current line up to the top of the
screen.'''
@@ -366,25 +338,21 @@ class screen:
self.fill_region (self.cur_r-1, 1, 1, self.cols)
def erase_screen (self): # <ESC>[2J
-
'''Erases the screen with the background color.'''
self.fill ()
def set_tab (self): # <ESC>H
-
'''Sets a tab at the current position.'''
pass
def clear_tab (self): # <ESC>[g
-
'''Clears tab at the current position.'''
pass
def clear_all_tabs (self): # <ESC>[3g
-
'''Clears all tabs.'''
pass