a ÿé!^ˆ5ã@sªdZddlZddlZddlZddlZejddddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZejddkZereZdd„ZGdd„dƒZdS)aÖ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 :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. éNz‡pexpect.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. ©)ÚnÚminÚmaxrrú2/usr/lib/python3.9/site-packages/pexpect/screen.pyÚ constrain<s rc@sšeZdZdZdbdd„Zdd „Zd d „Zer0eZn eZ d d „Zdd„Z dd„Z e fdd„Z e fdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zdcd/d0„Zddd1d2„Zded3d4„Zdfd5d6„Zdgd7d8„Zd9d:„Z d;d<„Z!d=d>„Z"d?d@„Z#dAdB„Z$dCdD„Z%dEdF„Z&dGdH„Z'dIdJ„Z(dKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,dSdT„Z-dUdV„Z.dWdX„Z/dYdZ„Z0d[d\„Z1d]d^„Z2d_d`„Z3daS)hÚscreena5This 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`. réPúlatin-1Úreplacecs||ˆ_|ˆ_|ˆ_|ˆ_|dur2t |¡|ƒˆ_ndˆ_dˆ_dˆ_dˆ_ dˆ_ dˆ_ ˆjˆ_ ‡fdd„t ˆjƒDƒˆ_dS)z8This initializes a blank screen of the given dimensions.Nécsg|]}tgˆj‘qSr)ÚSPACEÚcols)Ú.0Ú_©ÚselfrrÚ fóz#screen.__init__..)Úrowsr"ÚencodingÚencoding_errorsÚcodecsÚgetincrementaldecoderÚdecoderÚcur_rÚcur_cÚ cur_saved_rÚ cur_saved_cÚscroll_row_startÚscroll_row_endÚrangeÚw)r&ÚrÚcr*r+rr%rÚ__init__Uszscreen.__init__cCs"|jdur|j |¡Stdƒ‚dS)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._decodecCsd dd„|jDƒ¡S)zÂThis 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|]}d |¡‘qS©Ú©Újoin©r#r8rrrr'vr(z#screen._unicode..©rBr6r%rrrÚ_unicodeqszscreen._unicodecCs|jpd}| ¡ |d¡S)z{This returns a printable representation of the screen. The end of each screen line is terminated by a newline. Úasciir)r*rEÚencode)r&r*rrrÚ__str__}s zscreen.__str__cCsd dd„|jDƒ¡S)z£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.r@cSsg|]}d |¡‘qSr?rArCrrrr'ˆr(zscreen.dump..rDr%rrrÚdumpƒsz screen.dumpcCs<dd|jd}|d dd„t|ƒ d¡Dƒ¡d|S)z¸This 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|d‘qS)ú|r)r#Úlinerrrr'r(z!screen.pretty..)r"rBÚunicodeÚsplit)r&Ztop_botrrrÚprettyŠsz screen.prettycCs.t|tƒr| |¡}| dd|j|j|¡dS©Nr )Ú isinstanceÚbytesr=Ú fill_regionr)r"©r&ÚchrrrÚfill’s  z screen.fillcCsªt|tƒr| |¡}t|d|jƒ}t|d|jƒ}t|d|jƒ}t|d|jƒ}||kr^||}}||krp||}}t||dƒD]&}t||dƒD]}| |||¡qq~dSrQ)rRrSr=rr)r"r5Úput_abs)r&ÚrsÚcsÚreÚcerVr7r8rrrrT™s    zscreen.fill_regioncCs| |jd¡dS)zKThis moves the cursor to the beginning (col 1) of the current row. r N)Ú cursor_homer/r%rrrÚcrªsz screen.crcCs,|j}| ¡||jkr(| ¡| ¡dS)z3This moves the cursor down with scrolling. N)r/Ú cursor_downÚ scroll_upÚ erase_line©r&Zold_rrrrÚlf°s  z screen.lfcCs| ¡| ¡dS)ztThis advances the cursor with CRLF properties. The cursor will line wrap and the screen may scroll. N)r^rcr%rrrÚcrlfºsz screen.crlfcCs | ¡dS)z%This is an alias for crlf(). N)rdr%rrrÚnewlineÂszscreen.newlinecCsXt|d|jƒ}t|d|jƒ}t|tƒr6| |¡d}n|d}||j|d|d<dS)zScreen array starts at 1 index.r rN)rr)r"rRrSr=r6)r&r7r8rVrrrrXÈs  zscreen.put_abscCs*t|tƒr| |¡}| |j|j|¡dS)z?This puts a characters at the current cursor position. N)rRrSr=rXr/r0rUrrrÚputÓs  z screen.putc Cspt|tƒr| |¡}t|d|jƒ}t|d|jƒ}t|j|dƒD]}| ||| ||d¡¡q>| |||¡dS)z¥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. r éÿÿÿÿN) rRrSr=rr)r"r5rXÚget_abs)r&r7r8rVZcirrrÚ insert_absÜs  zscreen.insert_abscCs*t|tƒr| |¡}| |j|j|¡dS©N)rRrSr=rir/r0rUrrrÚinsertës  z screen.insertcCs2t|d|jƒ}t|d|jƒ}|j|d|dSrQ)rr)r"r6©r&r7r8rrrrhòszscreen.get_abscCs| |j|j¡dSrj)rhr/r0r%rrrÚgetøsz screen.getc Cs®t|d|jƒ}t|d|jƒ}t|d|jƒ}t|d|jƒ}||krJ||}}||kr\||}}g}t||dƒD]:}d}t||dƒD]}| ||¡} || }q„| |¡qn|S)z>This returns a list of lines representing the region. r r@)rr)r"r5rhÚappend) r&rYrZr[r\Zscr7rMr8rVrrrÚ get_regionüs      zscreen.get_regioncCs(t|jd|jƒ|_t|jd|jƒ|_dS)z6This keeps the cursor within the screen area. r N)rr/r)r0r"r%rrrÚcursor_constrainszscreen.cursor_constrainr cCs||_||_| ¡dSrj)r/r0rprlrrrr]szscreen.cursor_homecCs|j||_| ¡dSrj©r0rp©r&ÚcountrrrÚ cursor_backs zscreen.cursor_backcCs|j||_| ¡dSrj©r/rprrrrrr_#s zscreen.cursor_downcCs|j||_| ¡dSrjrqrrrrrÚcursor_forward(s zscreen.cursor_forwardcCs|j||_| ¡dSrjrurrrrrÚ cursor_up-s zscreen.cursor_upcCs$|j}| ¡||jkr | ¡dSrj)r/rwr`rbrrrÚcursor_up_reverse2s zscreen.cursor_up_reversecCs| ||¡dS)zIdentical to Cursor Home.N)r]rlrrrÚcursor_force_position9szscreen.cursor_force_positioncCs | ¡dS©zSave current cursor position.N)Úcursor_save_attrsr%rrrÚ cursor_save>szscreen.cursor_savecCs | ¡dS©z-Restores cursor position after a Save Cursor.N)Úcursor_restore_attrsr%rrrÚ cursor_unsaveCszscreen.cursor_unsavecCs|j|_|j|_dSrz)r/r1r0r2r%rrrr{Hszscreen.cursor_save_attrscCs| |j|j¡dSr})r]r1r2r%rrrr~Nszscreen.cursor_restore_attrscCs(|jdkrd|_|j|jkr$|j|_dS)z6This keeps the scroll region within the screen region.rr N)r3r4r)r%rrrÚscroll_constrainSs  zscreen.scroll_constraincCsd|_|j|_dS)z$Enable scrolling for entire display.r N)r3r)r4r%rrrÚ scroll_screen[szscreen.scroll_screencCs||_||_| ¡dS)z/Enable scrolling from row {start} to row {end}.N)r3r4r€)r&rYr[rrrÚscroll_screen_rowsaszscreen.scroll_screen_rowscCs>|jd}|jd}t |j||…¡|j|d|d…<dS)zScroll display down one line.r N©r3r4ÚcopyÚdeepcopyr6©r&r<ÚerrrÚ scroll_downhs  zscreen.scroll_downcCs>|jd}|jd}t |j|d|d…¡|j||…<dS)zScroll display up one line.r Nrƒr†rrrr`ps  zscreen.scroll_upcCs| |j|j|j|j¡dS)zOErases from the current cursor position to the end of the current line.N)rTr/r0r"r%rrrÚerase_end_of_linexszscreen.erase_end_of_linecCs| |jd|j|j¡dS)zQErases from the current cursor position to the start of the current line.r N)rTr/r0r%rrrÚerase_start_of_line~szscreen.erase_start_of_linecCs| |jd|j|j¡dS)zErases the entire current line.r N)rTr/r"r%rrrra„szscreen.erase_linecCs&| ¡| |jdd|j|j¡dS)zQErases the screen from the current line down to the bottom of the screen.r N)r‰rTr/r)r"r%rrrÚ erase_down‰szscreen.erase_downcCs$| ¡| |jddd|j¡dS)zLErases the screen from the current line up to the top of the screen.r N)rŠrTr/r"r%rrrÚerase_upszscreen.erase_upcCs | ¡dS)z,Erases the screen with the background color.N)rWr%rrrÚ erase_screen—szscreen.erase_screencCsdS)z#Sets a tab at the current position.Nrr%rrrÚset_tabœszscreen.set_tabcCsdS)z#Clears tab at the current position.Nrr%rrrÚ clear_tab¡szscreen.clear_tabcCsdS)zClears all tabs.Nrr%rrrÚclear_all_tabs¦szscreen.clear_all_tabsN)rrrr)r r )r )r )r )r )4Ú__name__Ú __module__Ú __qualname__Ú__doc__r9r=rEÚPY3rHZ __unicode__rIrPr!rWrTr^rcrdrerXrfrirkrhrmrorpr]rtr_rvrwrxryr|rr{r~r€rr‚rˆr`r‰rŠrar‹rŒrrŽrrrrrrrFsb            r)r”r,r„ÚsysÚwarningsÚwarnÚNULZENQZBELZBSZHTZLFÚVTZFFZCRZSOZSIZXONZXOFFZCANZSUBZESCZDELr!Ú version_infor•ÚstrrNrrrrrrÚs<ý