o !^5@sdZddlZddlZddlZddlZejddddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZejddkZerHeZddZGdddZdS)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  cCs||kr|S||kr |S|S)z@This returns a number, n constrained to the min and max bounds. )nminmaxrr0/usr/lib/python3/dist-packages/pexpect/screen.py constrain<s rc@seZdZdZdbddZdd Zd d ZereZneZ d d ZddZ ddZ e fddZ e fddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zdcd/d0Zddd1d2Zddd3d4Zddd5d6Zddd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$dCdDZ%dEdFZ&dGdHZ'dIdJZ(dKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-dUdVZ.dWdXZ/dYdZZ0d[d\Z1d]d^Z2d_d`Z3daS)escreena5This 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`. rPlatin-1replacecs||_|_|_|_|durt||_nd_d_d_d_ d_ d_ j_ fddt jD_dS)z8This initializes a blank screen of the given dimensions.Ncsg|]}tgjqSr)SPACEcols).0_selfrr fz#screen.__init__..)rowsr"encodingencoding_errorscodecsgetincrementaldecoderdecodercur_rcur_c cur_saved_r cur_saved_cscroll_row_startscroll_row_endrangew)r&rcr*r+rr%r__init__Uszscreen.__init__cCs|jdur |j|Std)ztThis converts from the external coding system (as passed to the constructor) to the internal one (unicode). NzLThis screen was constructed with encoding=None, so it does not handle bytes.)r.decode TypeError)r&srrr_decodehs  zscreen._decodecCddd|jDS)zThis returns a printable representation of the screen as a unicode string (which, under Python 3.x, is the same as 'str'). The end of each screen line is terminated by a newline. cSg|]}d|qSjoinr#r8rrrr'vz#screen._unicode..rDr6r%rrr_unicodeqzscreen._unicodecCs|jpd}||dS)z{This returns a printable representation of the screen. The end of each screen line is terminated by a newline. asciir)r*rHencode)r&r*rrr__str__}s zscreen.__str__cCr>)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.rBcSr@rArCrErrrr'rFzscreen.dump..rGr%rrrdumprIz screen.dumpcCs<dd|jd}|dddt|dDd|S)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?cSsg|]}d|dqS)|r)r#linerrrr'r(z!screen.pretty..)r"rDunicodesplit)r&top_botrrrprettys*z screen.prettycCs.t|tr ||}|dd|j|j|dSNr ) isinstancebytesr= fill_regionr)r"r&chrrrfills  z screen.fillcCst|tr ||}t|d|j}t|d|j}t|d|j}t|d|j}||kr/||}}||kr8||}}t||dD]}t||dD] }||||qHq?dSrV)rWrXr=rr)r"r5put_abs)r&rscsrecer[r7r8rrrrYs    zscreen.fill_regioncCs||jddS)zKThis moves the cursor to the beginning (col 1) of the current row. r N) cursor_homer/r%rrrcrsz screen.crcCs0|j}|||jkr||dSdS)z3This moves the cursor down with scrolling. N)r/ cursor_down scroll_up erase_liner&old_rrrrlfs   z screen.lfcCs||dS)ztThis advances the cursor with CRLF properties. The cursor will line wrap and the screen may scroll. N)rcrir%rrrcrlfs z screen.crlfcC |dS)z%This is an alias for crlf(). N)rjr%rrrnewlines zscreen.newlinecCsXt|d|j}t|d|j}t|tr||d}n|d}||j|d|d<dS)zScreen array starts at 1 index.r rN)rr)r"rWrXr=r6)r&r7r8r[rrrr]s  zscreen.put_abscCs*t|tr ||}||j|j|dS)z?This puts a characters at the current cursor position. N)rWrXr=r]r/r0rZrrrputs  z screen.putc Cspt|tr ||}t|d|j}t|d|j}t|j|dD]}||||||dq||||dS)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"r5r]get_abs)r&r7r8r[cirrr insert_abss  zscreen.insert_abscCs*t|tr ||}||j|j|dSN)rWrXr=rqr/r0rZrrrinserts  z screen.insertcCs2t|d|j}t|d|j}|j|d|dSrV)rr)r"r6r&r7r8rrrroszscreen.get_abscCs||j|jdSrr)ror/r0r%rrrgetsz screen.getc Cst|d|j}t|d|j}t|d|j}t|d|j}||kr%||}}||kr.||}}g}t||dD]}d}t||dD] }|||} || }qB||q7|S)z>This returns a list of lines representing the region. r rB)rr)r"r5roappend) r&r^r_r`rascr7rQr8r[rrr get_regions      zscreen.get_regioncCs(t|jd|j|_t|jd|j|_dS)z6This keeps the cursor within the screen area. r N)rr/r)r0r"r%rrrcursor_constrainszscreen.cursor_constrainr cCs||_||_|dSrr)r/r0ryrtrrrrbs zscreen.cursor_homecC|j||_|dSrrr0ryr&countrrr cursor_back  zscreen.cursor_backcC|j||_|dSrrr/ryr|rrrrd#rzscreen.cursor_downcCrrrr{r|rrrcursor_forward(rzscreen.cursor_forwardcCrzrrrr|rrr cursor_up-rzscreen.cursor_upcCs(|j}|||jkr|dSdSrr)r/rrergrrrcursor_up_reverse2s   zscreen.cursor_up_reversecCs|||dS)zIdentical to Cursor Home.N)rbrtrrrcursor_force_position9szscreen.cursor_force_positioncCrkzSave current cursor position.N)cursor_save_attrsr%rrr cursor_save> zscreen.cursor_savecCrkz-Restores cursor position after a Save Cursor.N)cursor_restore_attrsr%rrr cursor_unsaveCrzscreen.cursor_unsavecCs|j|_|j|_dSr)r/r1r0r2r%rrrrHs zscreen.cursor_save_attrscCs||j|jdSr)rbr1r2r%rrrrNszscreen.cursor_restore_attrscCs,|jdkrd|_|j|jkr|j|_dSdS)z6This keeps the scroll region within the screen region.rr N)r3r4r)r%rrrscroll_constrainSs   zscreen.scroll_constraincCsd|_|j|_dS)z$Enable scrolling for entire display.r N)r3r)r4r%rrr scroll_screen[s zscreen.scroll_screencCs||_||_|dS)z/Enable scrolling from row {start} to row {end}.N)r3r4r)r&r^r`rrrscroll_screen_rowsas zscreen.scroll_screen_rowscCs>|jd}|jd}t|j|||j|d|d<dS)zScroll display down one line.r Nr3r4copydeepcopyr6r&r<errr scroll_downh  *zscreen.scroll_downcCs>|jd}|jd}t|j|d|d|j||<dS)zScroll display up one line.r Nrrrrrreprzscreen.scroll_upcCs||j|j|j|jdS)zOErases from the current cursor position to the end of the current line.N)rYr/r0r"r%rrrerase_end_of_linexszscreen.erase_end_of_linecC||jd|j|jdS)zQErases from the current cursor position to the start of the current line.r N)rYr/r0r%rrrerase_start_of_line~szscreen.erase_start_of_linecCr)zErases the entire current line.r N)rYr/r"r%rrrrfszscreen.erase_linecCs&|||jdd|j|jdS)zQErases the screen from the current line down to the bottom of the screen.r N)rrYr/r)r"r%rrr erase_downszscreen.erase_downcCs$|||jddd|jdS)zLErases the screen from the current line up to the top of the screen.r N)rrYr/r"r%rrrerase_upszscreen.erase_upcCrk)z,Erases the screen with the background color.N)r\r%rrr erase_screenrzscreen.erase_screencCdS)z#Sets a tab at the current position.Nrr%rrrset_tabzscreen.set_tabcCr)z#Clears tab at the current position.Nrr%rrr clear_tabrzscreen.clear_tabcCr)zClears all tabs.Nrr%rrrclear_all_tabsrzscreen.clear_all_tabsN)rrrr)r r )r )4__name__ __module__ __qualname____doc__r9r=rHPY3rL __unicode__rMrUr!r\rYrcrirjrlr]rmrqrsrorurxryrbr~rdrrrrrrrrrrrrrerrrfrrrrrrrrrrrFsd             r)rr,rsyswarningswarnNULENQBELBSHTLFVTFFCRSOSIXONXOFFCANSUBESCDELr! version_inforstrrRrrrrrrs>