e5dZddlZddlZddlZddlZej dddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZej0ddk\ZereZdZGddZy)aThis 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 :class:`~pexpect.ANSI.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 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. Nzpexpect.screen and pexpect.ANSI are deprecated. We recommend using pyte to emulate a terminal screen: https://pypi.python.org/pypi/pyte) stacklevel  c"||kr|S||kDr|S|S)z@This returns a number, n constrained to the min and max bounds. )nminmaxs 0/usr/lib/python3/dist-packages/pexpect/screen.py constrainr<s! 3w 3w Hc@eZdZdZd0dZdZdZereZneZ dZdZ dZ e fdZ e fd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZd1dZd2dZd2dZd2dZd2dZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1d-Z2d.Z3y/)3screena5This object maintains the state of a virtual text screen as a rectangular 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 raise :exc:`TypeError`. cv||_||_||_||_|!t j |||_nd|_d|_d|_d|_ d|_ d|_ |j|_ t|jDcgc]}tg|jzc}|_ycc}w)z8This initializes a blank screen of the given dimensions.N)rowscolsencodingencoding_errorscodecsgetincrementaldecoderdecodercur_rcur_c cur_saved_r cur_saved_cscroll_row_startscroll_row_endrangeSPACEw)selfrcr%r&_s r__init__zscreen.__init__Us    .  A677A/RDLDL   !"ii05dii0@A1E7TYY&AAsB6cf|j|jj|Std)ztThis converts from the external coding system (as passed to the constructor) to the internal one (unicode). zLThis screen was constructed with encoding=None, so it does not handle bytes.)r)decode TypeError)r3ss r_decodezscreen._decodehs5 << #<<&&q) );< >rc|dj|jDcgc]}dj|c}Scc}w)zThis 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.r?r@rBs rdumpz screen.dumps- xx81388A;8998rDcdd|jzzdz}|djt|jdDcgc] }d|zdz c}zdz|zScc}w)zThis returns a copy of the screen as a unicode string with an ASCII text box around the screen border. This is similar to __str__/__unicode__ except that it adds a box.+-z+ r>|)r$rAunicodesplit)r3top_botlines rprettyz screen.prettysa dii'&0 @S@STY@Z$[T$Yt^$[\\_ddgnnn$[sA ct|tr|j|}|jdd|j|j |yNr") isinstancebytesr< fill_regionr#r$r3chs rfillz screen.fills8 b% b!B !Adii 26rct|tr|j|}t|d|j}t|d|j}t|d|j }t|d|j }||kDr||}}||kDr||}}t ||dzD])}t ||dzD]}|j|||+yrV)rWrXr<rr#r$r0put_abs)r3rscsrecer[r4r5s rrYzscreen.fill_regions b% b!B Atyy ) Atyy ) Atyy ) Atyy ) 7B 7BBqD! &ABQ' & a"% & &rc<|j|jdy)zKThis moves the cursor to the beginning (col 1) of the current row. r"N) cursor_homer*r3s rcrz screen.crs $**a(rc|j}|j||jk(r!|j|jyy)z3This moves the cursor down with scrolling. N)r* cursor_down scroll_up erase_liner3old_rs rlfz screen.lfs>   DJJ  NN  OO  rcD|j|jy)ztThis advances the cursor with CRLF properties. The cursor will line wrap and the screen may scroll. N)rfrmres rcrlfz screen.crlfs    rc$|jy)z%This is an alias for crlf(). N)rores rnewlinezscreen.newlines  rct|d|j}t|d|j}t|tr|j |d}n|d}||j |dz |dz <y)zScreen array starts at 1 index.r"rN)rr#r$rWrXr<r2)r3r4r5r[s rr^zscreen.put_abssh q!TYY ' q!TYY ' b% b!!$BABqs AaCrct|tr|j|}|j|j|j |y)z?This puts a characters at the current cursor position. N)rWrXr<r^r*r+rZs rputz screen.puts4 b% b!B djj$**b1rc Lt|tr|j|}t|d|j}t|d|j }t |j |dD](}|j|||j||dz *|j|||y)zThis 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. r"N) rWrXr<rr#r$r0r^get_abs)r3r4r5r[cis r insert_abszscreen.insert_abss b% b!B q!TYY ' q!TYY 'Ar* 6B LL!B Qr!t 4 5 6 a"rct|tr|j|}|j|j|j |yN)rWrXr<ryr*r+rZs rinsertz screen.inserts2 b% b!B TZZ4rct|d|j}t|d|j}|j|dz |dz SrV)rr#r$r2r3r4r5s rrwzscreen.get_abssA q!TYY ' q!TYY 'vvac{1Q3rcP|j|j|jyr{)rwr*r+res rgetz screen.gets djj$**-rct|d|j}t|d|j}t|d|j}t|d|j}||kDr||}}||kDr||}}g}t||dzD]@}d}t||dzD]}|j ||} || z}|j |B|S)z>This returns a list of lines representing the region. r"r?)rr#r$r0rwappend) r3r_r`rarbscr4rSr5r[s r get_regionzscreen.get_regionsAtyy ) Atyy ) Atyy ) Atyy ) 7B 7B BqD! ADBQ' !\\1Q'by ! IIt     rct|jd|j|_t|jd|j|_y)z6This keeps the cursor within the screen area. r"N)rr*r#r+r$res rcursor_constrainzscreen.cursor_constrains4 Atyy9  Atyy9 rc@||_||_|jyr{)r*r+rr~s rrdzscreen.cursor_homes    rcL|j|z |_|jyr{r+rr3counts r cursor_backzscreen.cursor_backZZ%'   rcL|j|z|_|jyr{r*rrs rrhzscreen.cursor_down#rrcL|j|z|_|jyr{rrs rcursor_forwardzscreen.cursor_forward(rrcL|j|z |_|jyr{rrs r cursor_upzscreen.cursor_up-rrc||j}|j||jk(r|jyyr{)r*rrirks rcursor_up_reversezscreen.cursor_up_reverse2s0   DJJ  NN  rc(|j||y)zIdentical to Cursor Home.N)rdr~s rcursor_force_positionzscreen.cursor_force_position9s !Qrc$|jyzSave current cursor position.N)cursor_save_attrsres r cursor_savezscreen.cursor_save>s  rc$|jyz-Restores cursor position after a Save Cursor.N)cursor_restore_attrsres r cursor_unsavezscreen.cursor_unsaveCs !!#rcH|j|_|j|_yr)r*r,r+r-res rrzscreen.cursor_save_attrsHs ::::rcP|j|j|jyr)rdr,r-res rrzscreen.cursor_restore_attrsNs  $**D,<,<=rc|jdkrd|_|j|jkDr|j|_yy)z6This keeps the scroll region within the screen region.rr"N)r.r/r#res rscroll_constrainzscreen.scroll_constrainSs=  A %$%D !    *"&))D  +rc4d|_|j|_y)z$Enable scrolling for entire display.r"N)r.r#r/res r scroll_screenzscreen.scroll_screen[s!""iirc@||_||_|jy)z/Enable scrolling from row {start} to row {end}.N)r.r/r)r3r_ras rscroll_screen_rowszscreen.scroll_screen_rowsas !#  rc|jdz }|jdz }tj|j|||j|dz|dzy)zScroll display down one line.r"Nr.r/copydeepcopyr2r3r;es r scroll_downzscreen.scroll_downhsN  ! !A %   ! #--q 4qs1Q3rc|jdz }|jdz }tj|j|dz|dz|j||y)zScroll display up one line.r"Nrrs rrizscreen.scroll_uppsN  ! !A %   ! #mmDFF1Q3qsO4q rc||j|j|j|j|jy)zOErases from the current cursor position to the end of the current line.N)rYr*r+r$res rerase_end_of_linezscreen.erase_end_of_linexs( $**djj$**diiHrch|j|jd|j|jy)zQErases from the current cursor position to the start of the current line.r"N)rYr*r+res rerase_start_of_linezscreen.erase_start_of_line~s$ $**aTZZ@rch|j|jd|j|jy)zErases the entire current line.r"N)rYr*r$res rrjzscreen.erase_lines$ $**aTYY?rc|j|j|jdzd|j|jy)zQErases the screen from the current line down to the bottom of the screen.r"N)rrYr*r#r$res r erase_downzscreen.erase_downs4 ! $**q.!TYY Brcz|j|j|jdz dd|jy)zLErases the screen from the current line up to the top of the screen.r"N)rrYr*r$res rerase_upzscreen.erase_ups0   # $**Q,1dii8rc$|jy)z,Erases the screen with the background color.N)r\res r erase_screenzscreen.erase_screens  rcy)z#Sets a tab at the current position.Nrres rset_tabzscreen.set_tab rcy)z#Clears tab at the current position.Nrres r clear_tabzscreen.clear_tabrrcy)zClears all tabs.Nrres rclear_all_tabszscreen.clear_all_tabsrrN)rPzlatin-1rG)r"r")r")4__name__ __module__ __qualname____doc__r7r<rCPY3rI __unicode__rKrTr1r\rYrfrmrorqr^rtryr|rwrrrrdrrhrrrrrrrrrrrrrirrrjrrrrrrrrrr r Fs B&<<   ? :o7-2&")  2 5 .*:! ! ! ! !  ! $ & > ,(  55I A @ C9    rr )rr'rsyswarningswarnNULENQBELBSHTLFVTFFCRSOSIXONXOFFCANSUBESCDELr1 version_inforstrrPrr rrrrs2   3     aG c c r