eaiovnaovbqoebvqoeavibavo 3 .]5@sdZddlZddlZddlZddlZejddddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZejddkZereZddZGdddZdS)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. )nminmaxrr/usr/lib/python3.6/screen.py constrain<s rc@seZdZdZdbddZdd Zd d Zer0eZn eZ d d ZddZ ddZ e fddZ e fddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zdcd/d0Zddd1d2Zded3d4Zdfd5d6Zdgd7d8Zd9d: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)hscreena5This 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||_|_|_|_|dk r2tj||_nd_d_d_d_ d_ d_ j_ fddt jD_dS)z8This initializes a blank screen of the given dimensions.Ncsg|]}tgjqSr)SPACEcols).0_)selfrr fsz#screen.__init__..)rowsr"encodingencoding_errorscodecsgetincrementaldecoderdecodercur_rcur_c cur_saved_r cur_saved_cscroll_row_startscroll_row_endrangew)r%rcr(r)r)r%r__init__Uszscreen.__init__cCs"|jdk r|jj|StddS)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._decodecCsdjdd|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. cSsg|]}dj|qS))join)r#r6rrrr&vsz#screen._unicode..)r>r4)r%rrr_unicodeqszscreen._unicodecCs|jpd}|jj|dS)z{This returns a printable representation of the screen. The end of each screen line is terminated by a newline. asciir)r(r?encode)r%r(rrr__str__}s zscreen.__str__cCsdjdd|jDS)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=cSsg|]}dj|qS)r=)r>)r#r6rrrr&szscreen.dump..)r>r4)r%rrrdumpsz screen.dumpcCs<dd|jd}|djddt|jdDd|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&sz!screen.pretty..)r"r>unicodesplit)r%Ztop_botrrrprettysz screen.prettycCs.t|tr|j|}|jdd|j|j|dS)Nr ) isinstancebytesr; fill_regionr'r")r%chrrrfills  z screen.fillcCst|tr|j|}t|d|j}t|d|j}t|d|j}t|d|j}||kr^||}}||krp||}}x}d}x*t||dD]}|j||} || }qW|j|qpW|S)z>This returns a list of lines representing the region. r r=)rr'r"r3r`append) r%rQrRrSrTZscr5rGr6rNrrr get_regions     zscreen.get_regioncCs(t|jd|j|_t|jd|j|_dS)z6This keeps the cursor within the screen area. r N)rr-r'r.r")r%rrrcursor_constrainszscreen.cursor_constrainr cCs||_||_|jdS)N)r-r.rf)r%r5r6rrrrUszscreen.cursor_homecCs|j||_|jdS)N)r.rf)r%countrrr cursor_backs zscreen.cursor_backcCs|j||_|jdS)N)r-rf)r%rgrrrrW#s zscreen.cursor_downcCs|j||_|jdS)N)r.rf)r%rgrrrcursor_forward(s zscreen.cursor_forwardcCs|j||_|jdS)N)r-rf)r%rgrrr cursor_up-s zscreen.cursor_upcCs$|j}|j||jkr |jdS)N)r-rjrX)r%rZrrrcursor_up_reverse2s zscreen.cursor_up_reversecCs|j||dS)zIdentical to Cursor Home.N)rU)r%r5r6rrrcursor_force_position9szscreen.cursor_force_positioncCs |jdS)zSave current cursor position.N)cursor_save_attrs)r%rrr cursor_save>szscreen.cursor_savecCs |jdS)z-Restores cursor position after a Save Cursor.N)cursor_restore_attrs)r%rrr cursor_unsaveCszscreen.cursor_unsavecCs|j|_|j|_dS)zSave current cursor position.N)r-r/r.r0)r%rrrrmHszscreen.cursor_save_attrscCs|j|j|jdS)z-Restores cursor position after a Save Cursor.N)rUr/r0)r%rrrroNszscreen.cursor_restore_attrscCs(|jdkrd|_|j|jkr$|j|_dS)z6This keeps the scroll region within the screen region.rr N)r1r2r')r%rrrscroll_constrainSs  zscreen.scroll_constraincCsd|_|j|_dS)z$Enable scrolling for entire display.r N)r1r'r2)r%rrr scroll_screen[szscreen.scroll_screencCs||_||_|jdS)z/Enable scrolling from row {start} to row {end}.N)r1r2rq)r%rQrSrrrscroll_screen_rowsaszscreen.scroll_screen_rowscCs>|jd}|jd}tj|j|||j|d|d<dS)zScroll display down one line.r N)r1r2copydeepcopyr4)r%r:errr scroll_downhs  zscreen.scroll_downcCs>|jd}|jd}tj|j|d|d|j||<dS)zScroll display up one line.r N)r1r2rtrur4)r%r:rvrrrrXps  zscreen.scroll_upcCs|j|j|j|j|jdS)zOErases from the current cursor position to the end of the current line.N)rMr-r.r")r%rrrerase_end_of_linexszscreen.erase_end_of_linecCs|j|jd|j|jdS)zQErases from the current cursor position to the start of the current line.r N)rMr-r.)r%rrrerase_start_of_line~szscreen.erase_start_of_linecCs|j|jd|j|jdS)zErases the entire current line.r N)rMr-r")r%rrrrYszscreen.erase_linecCs&|j|j|jdd|j|jdS)zQErases the screen from the current line down to the bottom of the screen.r N)rxrMr-r'r")r%rrr erase_downszscreen.erase_downcCs$|j|j|jddd|jdS)zLErases the screen from the current line up to the top of the screen.r N)ryrMr-r")r%rrrerase_upszscreen.erase_upcCs |jdS)z,Erases the screen with the background color.N)rO)r%rrr erase_screenszscreen.erase_screencCsdS)z#Sets a tab at the current position.Nr)r%rrrset_tabszscreen.set_tabcCsdS)z#Clears tab at the current position.Nr)r%rrr clear_tabszscreen.clear_tabcCsdS)zClears all tabs.Nr)r%rrrclear_all_tabsszscreen.clear_all_tabsN)rrrr)r r )r )r )r )r )4__name__ __module__ __qualname____doc__r7r;r?PY3rBZ __unicode__rCrJr!rOrMrVr[r\r]rPr^rarbr`rcrerfrUrhrWrirjrkrlrnrprmrorqrrrsrwrXrxryrYrzr{r|r}r~rrrrrrFsb            r)rr*rtsyswarningswarnZNULZENQZBELZBSZHTZLFZVTZFFZCRSOZSIZXONZXOFFZCANZSUBZESCZDELr! version_inforstrrHrrrrrrs: