
    k:i                    L   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ m!Z"m#Z$m%Z& dd
l'm(Z(   ed      e      Zde)d<    ed      Z* ed      Z+ G d de      Z, G d de      Z- G d de      Z. G d d      Z/ G d dee*e+f         Z0 e1e&jd                  e&jf                  g      Z4 G d d      Z5 G d de5      Z6 G d d e      Z7 G d! d"e5      Z8 G d# d$e      Z9 G d% d&      Z:y)'a  
    pyte.screens
    ~~~~~~~~~~~~

    This module provides classes for terminal screens, currently
    it contains three screens with different features:

    * :class:`~pyte.screens.Screen` -- base screen implementation,
      which handles all the core escape sequences, recognized by
      :class:`~pyte.streams.Stream`.
    * If you need a screen to keep track of the changed lines
      (which you probably do need) -- use
      :class:`~pyte.screens.DiffScreen`.
    * If you also want a screen to collect history and allow
      pagination -- :class:`pyte.screen.HistoryScreen` is here
      for ya ;)

    .. note:: It would be nice to split those features into mixin
              classes, rather than subclasses, but it's not obvious
              how to do -- feel free to submit a pull request.

    :copyright: (c) 2011-2012 by Selectel.
    :copyright: (c) 2012-2017 by pyte authors and contributors,
                    see AUTHORS for details.
    :license: LGPL, see LICENSE for more details.
    )annotationsN)dequedefaultdict)	lru_cache)AnyCallableDefaultDictDict	GeneratorList
NamedTupleOptionalSetSequenceTextIOTypeVar)wcwidth   )charsetscontrolgraphicsmodes)Streami   )maxsizezCallable[[str], int]r   KTVTc                  &    e Zd ZU dZded<   ded<   y)Marginsz(A container for screen's scroll margins.inttopbottomN__name__
__module____qualname____doc____annotations__     C/var/www/html/bot/venv/lib/python3.12/site-packages/pyte/screens.pyr   r   7   s    2	HKr)   r   c                  N    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   d	ed<   y)	SavepointzAA container for savepoint, created on :data:`~pyte.escape.DECSC`.Cursorcursorstr
g0_charset
g1_charsetr   charsetbooloriginwrapNr"   r(   r)   r*   r,   r,   <   s#    KNOOLL
Jr)   r,   c                      e Zd ZU dZded<   dZded<   dZded<   dZded	<   dZded
<   dZ	ded<   dZ
ded<   dZded<   dZded<   y)Chara  A single styled on-screen character.

    :param str data: unicode character. Invariant: ``len(data) == 1``.
    :param str fg: foreground colour. Defaults to ``"default"``.
    :param str bg: background colour. Defaults to ``"default"``.
    :param bool bold: flag for rendering the character using bold font.
                      Defaults to ``False``.
    :param bool italics: flag for rendering the character using italic font.
                         Defaults to ``False``.
    :param bool underscore: flag for rendering the character underlined.
                            Defaults to ``False``.
    :param bool strikethrough: flag for rendering the character with a
                               strike-through line. Defaults to ``False``.
    :param bool reverse: flag for swapping foreground and background colours
                         during rendering. Defaults to ``False``.
    :param bool blink: flag for rendering the character blinked. Defaults to
                       ``False``.
    r/   datadefaultfgbgFr3   bolditalics
underscorestrikethroughreverseblinkN)r#   r$   r%   r&   r'   r:   r;   r<   r=   r>   r?   r@   rA   r(   r)   r*   r7   r7   F   s^    $ IBBD$GTJM4GTE4r)   r7   c                  ,    e Zd ZdZdZ ed      fddZy)r-   a  Screen cursor.

    :param int x: 0-based horizontal cursor position.
    :param int y: 0-based vertical cursor position.
    :param pyte.screens.Char attrs: cursor attributes (see
        :meth:`~pyte.screens.Screen.select_graphic_rendition`
        for details).
    xyattrshidden c                <    || _         || _        || _        d| _        y )NFrC   )selfrD   rE   rF   s       r*   __init__zCursor.__init__o   s    
r)   N)rD   r   rE   r   rF   r7   returnNone)r#   r$   r%   r&   	__slots__r7   rK   r(   r)   r*   r-   r-   d   s     .I59#Y r)   r-   c                       e Zd ZdZddZddZy)StaticDefaultDicta  A :func:`dict` with a static default value.

    Unlike :func:`collections.defaultdict` this implementation does not
    implicitly update the mapping when queried with a missing key.

    >>> d = StaticDefaultDict(42)
    >>> d["foo"]
    42
    >>> d
    {}
    c                    || _         y Nr9   )rJ   r9   s     r*   rK   zStaticDefaultDict.__init__   s	    r)   c                    | j                   S rR   rS   )rJ   keys     r*   __missing__zStaticDefaultDict.__missing__   s    ||r)   N)r9   r   rL   rM   )rU   r   rL   r   )r#   r$   r%   r&   rK   rV   r(   r)   r*   rP   rP   v   s    
r)   rP   c                     e Zd ZdZed5d       Zd6dZd7dZed8d       Zd9dZ	d:d;dZ
d:d<d	Zd=d
Zd=dZd>dZd9dZd9dZd?dZd@dZd@dZd9dZd9dZd9dZd9dZd9dZd9dZd9dZd9dZdAdBdZdAdBdZdAdBdZdAdBdZdAdBdZ dCdDdZ!dEdFd Z"d9d!Z#dEdGd"Z$d9d#Z%dAdHd$Z&dAdBd%Z'dAdBd&Z(dAdBd'Z)dAdBd(Z*dAdBd)Z+dAdBd*Z,d:dId+Z-dAdJd,Z.dAdKd-Z/dLd.Z0d9d/Z1dMd0Z2dEdNd1Z3dOd2Z4d?d3Z5dPd4Z6y)QScreena  
    A screen is an in-memory matrix of characters that represents the
    screen display of the terminal. It can be instantiated on its own
    and given explicit commands, or it can be attached to a stream and
    will respond to events.

    .. attribute:: buffer

       A sparse ``lines x columns`` :class:`~pyte.screens.Char` matrix.

    .. attribute:: dirty

       A set of line numbers, which should be re-drawn. The user is responsible
       for clearing this set when changes have been applied.

       >>> screen = Screen(80, 24)
       >>> screen.dirty.clear()
       >>> screen.draw("!")
       >>> list(screen.dirty)
       [0]

       .. versionadded:: 0.7.0

    .. attribute:: cursor

       Reference to the :class:`~pyte.screens.Cursor` object, holding
       cursor position and attributes.

    .. attribute:: margins

       Margins determine which screen lines move during scrolling
       (see :meth:`index` and :meth:`reverse_index`). Characters added
       outside the scrolling region do not make the screen to scroll.

       The value is ``None`` if margins are set to screen boundaries,
       otherwise -- a pair 0-based top and bottom line indices.

    .. attribute:: charset

       Current charset number; can be either ``0`` or ``1`` for `G0`
       and `G1` respectively, note that `G0` is activated by default.

    .. note::

       According to ``ECMA-48`` standard, **lines and columns are
       1-indexed**, so, for instance ``ESC [ 10;10 f`` really means
       -- move cursor to position (9, 9) in the display matrix.

    .. versionchanged:: 0.4.7
    .. warning::

       :data:`~pyte.modes.LNM` is reset by default, to match VT220
       specification. Unfortunately this makes :mod:`pyte` fail
       ``vttest`` for cursor movement.

    .. versionchanged:: 0.4.8
    .. warning::

       If `DECAWM` mode is set than a cursor will be wrapped to the
       **beginning** of the next line, which is the behaviour described
       in ``man console_codes``.

    .. seealso::

       `Standard ECMA-48, Section 6.1.1        <http://ecma-international.org/publications/standards/Ecma-048.htm>`_
       for a description of the presentational component, implemented
       by ``Screen``.
    c                X    t         j                  | j                  v }t        ddd|      S )zAAn empty character with default foreground and background colors.rH   r9   )r8   r:   r;   r@   )moDECSCNMmoder7   )rJ   r@   s     r*   default_charzScreen.default_char   s'     **		)y'JJr)   c                     g  _         | _        | _        t         fd       _        t                _         j                          t        j                          _
        d  _        y )Nc                 H    t        t        t        f    j                        S rR   )rP   r   r7   r]   rJ   s   r*   <lambda>z!Screen.__init__.<locals>.<lambda>   s,    SdehjnenSopt  qB  qB  TC r)   )
savepointscolumnslinesr   buffersetdirtyreset_DEFAULT_MODEcopyr\   margins)rJ   rc   rd   s   `  r*   rK   zScreen.__init__   sV    +-
?J  LC  @D"u


!&&(	*.r)   c                x    dj                  | j                  j                  | j                  | j                        S )Nz{0}({1}, {2}))format	__class__r#   rc   rd   r`   s    r*   __repr__zScreen.__repr__   s0    &&t~~'>'>'+||TZZA 	Br)   c           	          d fd}t         j                        D cg c]&  }dj                   | j                  |               ( c}S c c}w )z2A :func:`list` of screen lines as unicode strings.c           	   3     K   d}t        j                        D ]L  }|rd}| |   j                  }t        t	        t
        |dd              dk(  sJ t        |d         dk(  }| N y w)NFr   r      )rangerc   r8   summapr   )lineis_wide_charrD   charrJ   s       r*   renderzScreen.display.<locals>.render   st      L4<<( #(LAw||3wQR12a777&tAw/14
s   A(A+ )rv   zStaticDefaultDict[int, Char]rL   zGenerator[str, None, None])rs   rd   joinre   )rJ   ry   rE   s   `  r*   displayzScreen.display   s=    		 :?tzz9JKAt{{1~./KKKs   +Ac                   | j                   j                  t        | j                               | j                  j                          d| _        t        j                         | _	        d| _
        d| _        d| _        t        j                  | _        t        j                   | _        t%        t        d| j&                  d            | _        t+        dd      | _        | j/                          d| _        y)a}  Reset the terminal to its initial state.

        * Scrolling margins are reset to screen boundaries.
        * Cursor is moved to home location -- ``(0, 0)`` and its
          attributes are set to defaults (see :attr:`default_char`).
        * Screen is cleared -- each character is reset to
          :attr:`default_char`.
        * Tabstops are reset to "every eight columns".
        * All lines are marked as :attr:`dirty`.

        .. note::

           Neither VT220 nor VT102 manuals mention that terminal modes
           and tabstops should be reset as well, thanks to
           :manpage:`xterm` -- we now know that.
        Nrz   r      )rg   updaters   rd   re   clearrk   ri   rj   r\   title	icon_namer2   csLAT1_MAPr0   	VT100_MAPr1   rf   rc   tabstopsr-   r.   cursor_positionsaved_columnsr`   s    r*   rh   zScreen.reset   s    " 	

%

+,!&&(	
++,,
 E!T\\156Ql,0r)   Nc                |   |xs | j                   }|xs | j                  }|| j                   k(  r|| j                  k(  ry| j                  j                  t	        |             || j                   k  rP| j                          | j                  dd       | j                  | j                   |z
         | j                          || j                  k  rL| j                  j                         D ]/  }t	        || j                        D ]  }|j                  |d        1 ||c| _         | _        | j                          y)a  Resize the screen to the given size.

        If the requested screen size has more lines than the existing
        screen, lines will be added at the bottom. If the requested
        size has less lines than the existing screen lines will be
        clipped at the top of the screen. Similarly, if the existing
        screen has less columns than the requested screen, columns will
        be added at the right, and if it has more -- columns will be
        clipped at the right.

        :param int lines: number of lines in the new screen.
        :param int columns: number of columns in the new screen.

        .. versionchanged:: 0.7.0

           If the requested screen size is identical to the current screen
           size, the method does nothing.
        Nr   )rd   rc   rg   r   rs   save_cursorr   delete_linesrestore_cursorre   valuespopset_margins)rJ   rd   rc   rv   rD   s        r*   resizezScreen.resize  s	   & #)T\\DJJ7dll#:

%,'4::  A&djj501!T\\!**, &w5 &AHHQ%&& $)' 
DLr)   c                   ||dk(  r
|d| _         y| j                   xs t        d| j                  dz
        }||j                  }n&t	        dt        |dz
  | j                  dz
              }||j                  }n&t	        dt        |dz
  | j                  dz
              }||z
  dk\  r"t        ||      | _         | j                          yy)zSelect top and bottom margins for the scrolling region.

        :param int top: the smallest line number that is scrolled.
        :param int bottom: the biggest line number that is scrolled.
        Nr   r   )rk   r   rd   r    maxminr!   r   )rJ   r    r!   rk   s       r*   r   zScreen.set_marginsG  s     K3!8DL,,<'!TZZ!^"<
 ;++CaS1Wdjj1n56C>^^FC
DJJN;<F
 C<1"3/DL   " r)   c                <   t        |      }|j                  d      rR|D cg c]  }|dz  	 }}t        j                  |v r.| j                  j                  t        | j                               | j                  j                  |       t        j                  |v rD| j                  | _        | j                  d       | j                  d       | j                          t        j                  |v r| j                          t        j                  |v r`| j                   j#                         D ]2  }| j$                  |_        |D ]  }||   j)                  d      ||<    4 | j+                  d       t        j,                  |v rd	| j.                  _        y
y
c c}w )zSet (enable) a given list of modes.

        :param list modes: modes to set, where each mode is a constant
                           from :mod:`pyte.modes`.
        private      rc   rr   Tr@      FN)listgetrZ   r[   rg   r   rs   rd   r\   DECCOLMrc   r   r   erase_in_displayr   DECOMre   r   r]   r9   _replaceselect_graphic_renditionDECTCEMr.   rG   rJ   r   kwargs	mode_listr\   rv   rD   s          r*   set_modezScreen.set_modej  s\    K	 ::i /45t5I5zzY&

!!%

"34		# ::"!%DKKK$!!!$  " 88y   " ::"**, =#00 =A"1g..t.<DG==
 ))!, ::"!&DKK #9 6s   Fc                r   t        |      }|j                  d      rR|D cg c]  }|dz  	 }}t        j                  |v r.| j                  j                  t        | j                               | j                  j                  |       t        j                  |v r_| j                  dk(  r/| j                  #| j                  | j                         d| _        | j                  d       | j                          t        j                   |v r| j                          t        j                  |v r`| j"                  j%                         D ]2  }| j&                  |_        |D ]  }||   j+                  d      ||<    4 | j-                  d	       t        j.                  |v rd
| j0                  _        yyc c}w )zReset (disable) a given list of modes.

        :param list modes: modes to reset -- hopefully, each mode is a
                           constant from :mod:`pyte.modes`.
        r   r   r   Nr   rr   Fr      T)r   r   rZ   r[   rg   r   rs   rd   r\   difference_updater   rc   r   r   r   r   r   re   r   r]   r9   r   r   r   r.   rG   r   s          r*   
reset_modezScreen.reset_mode  sq    K	 ::i /45t5I5zzY&

!!%

"34		##I. ::"||s"t'9'9'ED$6$67%)"!!!$  "88y   "::"**, >#00 >A"1g..u.=DG>>
 ))"- ::"!%DKK #5 6s   F4c                    |t         j                  v r=|dk(  rt         j                  |   | _        y|dk(  rt         j                  |   | _        yyy)ao  Define ``G0`` or ``G1`` charset.

        :param str code: character set code, should be a character
                         from ``"B0UK"``, otherwise ignored.
        :param str mode: if ``"("`` ``G0`` charset is defined, if
                         ``")"`` -- we operate on ``G1``.

        .. warning:: User-defined charsets are currently not supported.
        ()N)r   MAPSr0   r1   )rJ   coder\   s      r*   define_charsetzScreen.define_charset  sE     277?s{"$''$-"$''$-  r)   c                    d| _         y)zSelect ``G0`` character set.r   Nr2   r`   s    r*   shift_inzScreen.shift_in  	    r)   c                    d| _         y)zSelect ``G1`` character set.r   Nr   r`   s    r*   	shift_outzScreen.shift_out  r   r)   c                   |j                  | j                  r| j                  n| j                        }|D ]  }t	        |      }| j
                  j                  | j                  k(  rt        j                  | j                  v rP| j                  j                  | j
                  j                         | j                          | j                          n$|dkD  r| j
                  xj                  |z  c_        t        j                   | j                  v r|dkD  r| j#                  |       | j$                  | j
                  j                     }|dk(  r?| j
                  j&                  j)                  |      || j
                  j                  <   n|dk(  r| j
                  j&                  j)                  |      || j
                  j                  <   | j
                  j                  dz   | j                  k  r| j
                  j&                  j)                  d      || j
                  j                  dz   <   nV|dk(  rNt+        j,                  |      r8| j
                  j                  rl|| j
                  j                  dz
     }t+        j.                  d|j0                  |z         }|j)                  |      || j
                  j                  dz
  <   n| j
                  j                  r| j$                  | j
                  j                  dz
     | j                  dz
     }t+        j.                  d|j0                  |z         }|j)                  |      | j$                  | j
                  j                  dz
     | j                  dz
  <   n nF|dkD  sct3        | j
                  j                  |z   | j                        | j
                  _         | j                  j                  | j
                  j                         y)a  Display decoded characters at the current cursor position and
        advances the cursor if :data:`~pyte.modes.DECAWM` is set.

        :param str data: text to display.

        .. versionchanged:: 0.5.0

           Character width is taken into account. Specifically, zero-width
           and unprintable characters do not affect screen state. Full-width
           characters are rendered into two consecutive character containers.
        r   r   r8   rr   rz   NFCN)	translater2   r1   r0   r   r.   rD   rc   rZ   DECAWMr\   rg   addrE   carriage_returnlinefeedIRMinsert_charactersre   rF   r   unicodedata	combining	normalizer8   r   )rJ   r8   rx   
char_widthrv   last
normalizeds          r*   drawzScreen.draw  s    ~~#||DOOB  0	ND J {{}},99		)JJNN4;;==1((*MMO!^KKMMZ/M
 vv"zA~&&z2;;t{{}}-DQ&*kk&7&7&@&@d&@&KT[[]]#q&*kk&7&7&@&@d&@&KT[[]]#;;==1$t||3.2kk.?.?!r* *+q[%:%:4%@ ;;== 12D!,!6!6udii$>N!OJ.2mmm.LD*+[[]];;t{{}}q'89$,,:JKD!,!6!6udii$>N!OJ:6 KK 124<<!3CD  A~ #DKKMMJ$> Ma0	Nd 	

t{{}}%r)   c                    || _         y)zkSet terminal title.

        .. note:: This is an XTerm extension supported by the Linux terminal.
        N)r   rJ   params     r*   	set_titlezScreen.set_title  s    
 
r)   c                    || _         y)zfSet icon name.

        .. note:: This is an XTerm extension supported by the Linux terminal.
        N)r   r   s     r*   set_icon_namezScreen.set_icon_name  s    
 r)   c                &    d| j                   _        y)z5Move the cursor to the beginning of the current line.r   N)r.   rD   r`   s    r*   r   zScreen.carriage_return#  s    r)   c                   | j                   xs t        d| j                  dz
        \  }}| j                  j                  |k(  r{| j
                  j                  t        | j                               t        ||      D ]!  }| j                  |dz      | j                  |<   # | j                  j                  |d       y| j                          y)zMove the cursor down one line in the same column. If the
        cursor is at the last line, create a new line at the bottom.
        r   r   N)rk   r   rd   r.   rE   rg   r   rs   re   r   cursor_downrJ   r    r!   rE   s       r*   indexzScreen.index'  s     ll@gaa&@V;;==F"JJeDJJ/03' 4!%QU!3A4KKOOFD)r)   c                   | j                   xs t        d| j                  dz
        \  }}| j                  j                  |k(  r|| j
                  j                  t        | j                               t        ||d      D ]!  }| j                  |dz
     | j                  |<   # | j                  j                  |d       y| j                          y)zMove the cursor up one line in the same column. If the cursor
        is at the first line, create a new line at the top.
        r   r   N)rk   r   rd   r.   rE   rg   r   rs   re   r   	cursor_upr   s       r*   reverse_indexzScreen.reverse_index5  s     ll@gaa&@V;;==CJJeDJJ/063+ 4!%QU!3A4KKOOC&NNr)   c                ~    | j                          t        j                  | j                  v r| j	                          yy)z\Perform an index and, if :data:`~pyte.modes.LNM` is set, a
        carriage return.
        N)r   rZ   LNMr\   r   r`   s    r*   r   zScreen.linefeedC  s.     	

66TYY  " r)   c                    t        | j                        D ]  }| j                  j                  |k  s|} n | j                  dz
  }|| j                  _        y)zcMove to the next tab space, or the end of the screen if there
        aren't anymore left.
        r   N)sortedr   r.   rD   rc   )rJ   stopcolumns      r*   tabz
Screen.tabL  sO     4==) 	&D{{}}t#	&
 \\A%Fr)   c                $    | j                          y)zuMove cursor to the left one or keep it in its position if
        it's at the beginning of the line already.
        N)cursor_backr`   s    r*   	backspacezScreen.backspaceY  s     	r)   c                4   | j                   j                  t        t        j                  | j                        | j
                  | j                  | j                  t        j                  | j                  v t        j                  | j                  v              y)z0Push the current cursor position onto the stack.N)rb   appendr,   rj   r.   r0   r1   r2   rZ   r   r\   r   r`   s    r*   r   zScreen.save_cursor_  sa    y4;;)?)-)-)-)+TYY)>)+dii)? A 	Br)   c                (   | j                   r| j                   j                         }|j                  | _        |j                  | _        |j                  | _        |j
                  r| j                  t        j                         |j                  r| j                  t        j                         |j                  | _        | j                          | j                  d       y| j                  t        j                         | j                          y)z[Set the current cursor position to whatever cursor is on top
        of the stack.
        T)use_marginsN)rb   r   r0   r1   r2   r4   r   rZ   r   r5   r   r.   ensure_hboundsensure_vboundsr   r   )rJ   	savepoints     r*   r   zScreen.restore_cursorh  s     ??++-I'22DO'22DO$,,DLbhh'~~bii(#**DK!D1 OOBHH%  "r)   c                D   |xs d}| j                   xs t        d| j                  dz
        \  }}|| j                  j                  cxk  r|k  rn y| j
                  j                  t        | j                  j                  | j                               t        || j                  j                  dz
  d      D ]S  }||z   |k  r-|| j                  v r| j                  |   | j                  ||z   <   | j                  j                  |d       U | j                          yy)zInsert the indicated # of lines at line with cursor. Lines
        displayed **at** and below the cursor move down. Lines moved
        past the bottom margin are lost.

        :param count: number of lines to insert.
        r   r   r   Nrk   r   rd   r.   rE   rg   r   rs   re   r   r   rJ   countr    r!   rE   s        r*   insert_lineszScreen.insert_lines  s     
ll@gaa&@V $++--)6)JJeDKKMM4::>?64;;==1#4b9 )u9&1+;-1[[^DKKE	*4()
   " *r)   c                d   |xs d}| j                   xs t        d| j                  dz
        \  }}|| j                  j                  cxk  r|k  rn y| j
                  j                  t        | j                  j                  | j                               t        | j                  j                  |dz         D ]d  }||z   |k  r>||z   | j                  v s| j                  j                  ||z         | j                  |<   I| j                  j                  |d       f | j                          yy)a3  Delete the indicated # of lines, starting at line with
        cursor. As lines are deleted, lines displayed below cursor
        move up. Lines added to bottom of screen have spaces with same
        character attributes as last line moved up.

        :param int count: number of lines to delete.
        r   r   Nr   r   s        r*   r   zScreen.delete_lines  s     
ll@gaa&@V $++--)6)JJeDKKMM4::>?4;;==&1*5 -u9&5yDKK/)-U)CAKKOOAt,-   " *r)   c                x   | j                   j                  | j                  j                         |xs d}| j                  | j                  j                     }t        | j                  | j                  j                  dz
  d      D ]1  }||z   | j                  k  r||   |||z   <   |j                  |d       3 y)a  Insert the indicated # of blank characters at the cursor
        position. The cursor does not move and remains at the beginning
        of the inserted blank characters. Data on the line is shifted
        forward.

        :param int count: number of characters to insert.
        r   r   N)	rg   r   r.   rE   re   rs   rc   rD   r   rJ   r   rv   rD   s       r*   r   zScreen.insert_characters  s     	

t{{}}%
{{4;;==)t||T[[]]Q%6; 	A5yDLL("&q'QYHHQ	r)   c                   | j                   j                  | j                  j                         |xs d}| j                  | j                  j                     }t        | j                  j                  | j                        D ]I  }||z   | j                  k  r#|j                  ||z   | j                        ||<   8|j                  |d       K y)a.  Delete the indicated # of characters, starting with the
        character at cursor position. When a character is deleted, all
        characters to the right of cursor move left. Character attributes
        move with the characters.

        :param int count: number of characters to delete.
        r   N)
rg   r   r.   rE   re   rs   rD   rc   r   r]   r   s       r*   delete_characterszScreen.delete_characters  s     	

t{{}}%
{{4;;==)t{{}}dll3 	"A5yDLL(((1u9d.?.?@QD!		"r)   c                   | j                   j                  | j                  j                         |xs d}| j                  | j                  j                     }t        | j                  j                  t        | j                  j                  |z   | j                              D ]  }| j                  j                  ||<    y)a&  Erase the indicated # of characters, starting with the
        character at cursor position. Character attributes are set
        cursor attributes. The cursor remains in the same position.

        :param int count: number of characters to erase.

        .. note::

           Using cursor attributes for character attributes may seem
           illogical, but if recall that a terminal emulator emulates
           a type writer, it starts to make sense. The only way a type
           writer could erase a character is by typing over it.
        r   N)
rg   r   r.   rE   re   rs   rD   r   rc   rF   r   s       r*   erase_characterszScreen.erase_characters  s     	

t{{}}%
{{4;;==)t{{}}4;;==50$,,?A 	(Akk''DG	(r)   c                   | j                   j                  | j                  j                         |dk(  r+t	        | j                  j
                  | j                        }nB|dk(  r#t	        | j                  j
                  dz         }n|dk(  rt	        | j                        }| j                  | j                  j                     }D ]  }| j                  j                  ||<    y)a2  Erase a line in a specific way.

        Character attributes are set to cursor attributes.

        :param int how: defines the way the line should be erased in:

            * ``0`` -- Erases from cursor to end of line, including cursor
              position.
            * ``1`` -- Erases from beginning of line to cursor,
              including cursor position.
            * ``2`` -- Erases complete line.
        :param bool private: when ``True`` only characters marked as
                             erasable are affected **not implemented**.
        r   r   rr   N)	rg   r   r.   rE   rs   rD   rc   re   rF   )rJ   howr   intervalrv   rD   s         r*   erase_in_linezScreen.erase_in_line  s     	

t{{}}%!8T[[]]DLL9HAXT[[]]Q./HAXT\\*H{{4;;==) 	(Akk''DG	(r)   c                   |dk(  r.t        | j                  j                  dz   | j                        }nD|dk(  r t        | j                  j                        }n|dk(  s|dk(  rt        | j                        }| j                  j                         |D ]1  }| j                  |   }|D ]  }| j                  j                  ||<    3 |dk(  s|dk(  r| j                  |       yy)a  Erases display in a specific way.

        Character attributes are set to cursor attributes.

        :param int how: defines the way the line should be erased in:

            * ``0`` -- Erases from cursor to end of screen, including
              cursor position.
            * ``1`` -- Erases from beginning of screen to cursor,
              including cursor position.
            * ``2`` and ``3`` -- Erases complete display. All lines
              are erased and changed to single-width. Cursor does not
              move.
        :param bool private: when ``True`` only characters marked as
                             erasable are affected **not implemented**.

        .. versionchanged:: 0.8.1

           The method accepts any number of positional arguments as some
           ``clear`` implementations include a ``;`` after the first
           parameter causing the stream to assume a ``0`` second parameter.
        r   r   rr      N)	rs   r.   rE   rd   rg   r   re   rF   r   )rJ   r   argsr   r   rE   rv   rD   s           r*   r   zScreen.erase_in_display   s    . !8T[[]]Q.

;HAXT[[]]+HAXTZZ(H

(# 	,A;;q>D ,++++Q,	,
 !8saxs#  r)   c                b    | j                   j                  | j                  j                         y)z-Set a horizontal tab stop at cursor position.N)r   r   r.   rD   r`   s    r*   set_tab_stopzScreen.set_tab_stop'  s    $++--(r)   c                    |dk(  r0| j                   j                  | j                  j                         y|dk(  rt	               | _         yy)a  Clear a horizontal tab stop.

        :param int how: defines a way the tab stop should be cleared:

            * ``0`` or nothing -- Clears a horizontal tab stop at cursor
              position.
            * ``3`` -- Clears all horizontal tab stops.
        r   r   N)r   discardr.   rD   rf   )rJ   r   s     r*   clear_tab_stopzScreen.clear_tab_stop+  s<     !8 MM!!$++--0AXEDM r)   c                    t        t        d| j                  j                        | j                  dz
        | j                  _        y)z5Ensure the cursor is within horizontal screen bounds.r   r   N)r   r   r.   rD   rc   r`   s    r*   r   zScreen.ensure_hbounds;  s,    C4;;==14<<!3CDr)   c                   |st         j                  | j                  v r| j                  | j                  \  }}nd| j                  dz
  }}t        t        || j                  j                        |      | j                  _        y)aI  Ensure the cursor is within vertical screen bounds.

        :param bool use_margins: when ``True`` or when
                                 :data:`~pyte.modes.DECOM` is set,
                                 cursor is bounded by top and and bottom
                                 margins, instead of ``[0; lines - 1]``.
        Nr   r   )	rZ   r   r\   rk   rd   r   r   r.   rE   )rJ   r   r    r!   s       r*   r   zScreen.ensure_vbounds?  s^     288tyy0dll6N,,KCTZZ!^CCT[[]]3V<r)   c                    | j                   xs t        d| j                  dz
        \  }}t        | j                  j
                  |xs dz
  |      | j                  _        y)zMove cursor up the indicated # of lines in same column.
        Cursor stops at top margin.

        :param int count: number of lines to skip.
        r   r   N)rk   r   rd   r   r.   rE   )rJ   r   r    _bottoms       r*   r   zScreen.cursor_upN  sH     ||Awq$**q.'AWDKKMMUZa8#>r)   c                F    | j                  |       | j                          y)zMove cursor up the indicated # of lines to column 1. Cursor
        stops at bottom margin.

        :param int count: number of lines to skip.
        N)r   r   rJ   r   s     r*   
cursor_up1zScreen.cursor_up1W  s     	ur)   c                    | j                   xs t        d| j                  dz
        \  }}t        | j                  j
                  |xs dz   |      | j                  _        y)zMove cursor down the indicated # of lines in same column.
        Cursor stops at bottom margin.

        :param int count: number of lines to skip.
        r   r   N)rk   r   rd   r   r.   rE   )rJ   r   _topr!   s       r*   r   zScreen.cursor_down`  sH     ||Awq$**q.'AfDKKMMUZa8&Ar)   c                F    | j                  |       | j                          y)zMove cursor down the indicated # of lines to column 1.
        Cursor stops at bottom margin.

        :param int count: number of lines to skip.
        N)r   r   r  s     r*   cursor_down1zScreen.cursor_down1i  s     	r)   c                    | j                   j                  | j                  k(  r| j                   xj                  dz  c_        | j                   xj                  |xs dz  c_        | j                          y)zMove cursor left the indicated # of columns. Cursor stops
        at left margin.

        :param int count: number of columns to skip.
        r   N)r.   rD   rc   r   r  s     r*   r   zScreen.cursor_backr  sL     ;;==DLL(KKMMQM!#r)   c                j    | j                   xj                  |xs dz  c_        | j                          y)zMove cursor right the indicated # of columns. Cursor stops
        at right margin.

        :param int count: number of columns to skip.
        r   Nr.   rD   r   r  s     r*   cursor_forwardzScreen.cursor_forward  s&     	!#r)   c                   |xs ddz
  }|xs ddz
  }| j                   kt        j                  | j                  v rO|| j                   j                  z  }| j                   j                  |cxk  r| j                   j
                  k  sy y|| j                  _        || j                  _        | j                          | j                          y)a^  Set the cursor to a specific `line` and `column`.

        Cursor is allowed to move out of the scrolling region only when
        :data:`~pyte.modes.DECOM` is reset, otherwise -- the position
        doesn't change.

        :param int line: line number to move the cursor to.
        :param int column: column number to move the cursor to.
        r   N)rk   rZ   r   r\   r    r!   r.   rD   rE   r   r   )rJ   rv   r   s      r*   r   zScreen.cursor_position  s     +A"	Q <<#DII(=DLL$$$D <<##tBt||/B/BB Cr)   c                T    |xs ddz
  | j                   _        | j                          y)zMove cursor to a specific column in the current line.

        :param int column: column number to move the cursor to.
        r   Nr  )rJ   r   s     r*   cursor_to_columnzScreen.cursor_to_column  s$    
  1)r)   c                   |xs ddz
  | j                   _        t        j                  | j                  v rA| j
                  J | j                   xj                  | j
                  j                  z  c_        | j                          y)z{Move cursor to a specific line in the current column.

        :param int line: line number to move the cursor to.
        r   N)r.   rE   rZ   r   r\   rk   r    r   )rJ   rv   s     r*   cursor_to_linezScreen.cursor_to_line  sc    
 a 88tyy <<+++KKMMT\\---M
 	r)   c                     y)zdBell stub -- the actual implementation should probably be
        provided by the end-user.
        Nr(   )rJ   r   s     r*   bellzScreen.bell      r)   c                ,   | j                   j                  t        | j                               t        | j                        D ]N  }t        | j                        D ]4  }| j
                  |   |   j                  d      | j
                  |   |<   6 P y)z?Fills screen with uppercase E's for screen focus and alignment.Er   N)rg   r   rs   rd   rc   re   r   )rJ   rE   rD   s      r*   alignment_displayzScreen.alignment_display  s~    

%

+,tzz" 	IA4<<( I$(KKN1$5$>$>C$>$HAq!I	Ir)   c                   i }|r|dk(  r| j                   | j                  _        yt        t	        |            }|r|j                         }|dk(  r+|j                  | j                   j                                n|t        j                  v rt        j                  |   |d<   n|t        j                  v rt        j                  |   |d<   ne|t        j                  v r,t        j                  |   }|j                  d      ||dd <   n'|t        j                  v r$|j                  t        j                  |          n|t        j                  v r$|j                  t        j                  |   	       n|t        j                   t        j"                  fv r|t        j                   k(  rdnd}	 |j                         }|d
k(  r'|j                         }t        j$                  |   ||<   nE|dk(  r@dj'                  |j                         |j                         |j                               ||<   |r | j                  j                  j*                  di || j                  _        y# t(        $ r Y Ew xY w)zaSet display attributes.

        :param list attrs: a list of display attributes to set.
        r   Nr   r:   r;   +r   )r:   )r;   r   rr   z{0:02x}{1:02x}{2:02x}r(   )r]   r.   rF   r   reversedr   r   _asdictgFG_ANSIBGBG_ANSITEXT
startswith
FG_AIXTERM
BG_AIXTERMFG_256BG_256	FG_BG_256rm   
IndexErrorr   )	rJ   rF   replace
attrs_listattrattr_strrU   nms	            r*   r   zScreen.select_graphic_rendition  s   
   $ 1 1DKK(5/*
>>#Dqyt0088:;" !		$ !		$66$<(0(;(;C(@%%!,,t"45%!,,t"45!((AHH--"ahh.dD"(AAv&NN,'({{1~a (?'E'E&NN,jnn.>
@P(R7 @ 7DKK--66AA " s   5BI0 0	I<;I<c                x    |dk(  r5|j                  d      s#| j                  t        j                  dz          yyy)zReport terminal identity.

        .. versionadded:: 0.5.0

        .. versionchanged:: 0.7.0

           If ``private`` keyword argument is set, the method does nothing.
           This behaviour is consistent with VT220 manual.
        r   r   z?6cN)r   write_process_inputctrlCSI)rJ   r\   r   s      r*   report_device_attributeszScreen.report_device_attributes  s4     19VZZ	2$$TXX%56 39r)   c                   |dk(  r#| j                  t        j                  dz          y|dk(  r| j                  j                  dz   }| j                  j
                  dz   }t        j                  | j                  v r'| j                  J || j                  j                  z  }| j                  t        j                  dj                  ||      z          yy)zReport terminal status or cursor position.

        :param int mode: if 5 -- terminal status, 6 -- cursor position,
                         otherwise a noop.

        .. versionadded:: 0.5.0
        r   0n   r   Nz{0};{1}R)r2  r3  r4  r.   rD   rE   rZ   r   r\   rk   r    rm   )rJ   r\   rD   rE   s       r*   report_device_statuszScreen.report_device_status	  s     19$$TXX_5QY!A!A xx499$||///T\\%%%$$TXX
0A0A!Q0G%GH r)   c                     y)zWrite data to the process running inside the terminal.

        By default is a noop.

        :param str data: text to write to the process ``stdin``.

        .. versionadded:: 0.5.0
        Nr(   )rJ   r8   s     r*   r2  zScreen.write_process_input  r  r)   c                     y)zSEndpoint for unrecognized escape sequences.

        By default is a noop.
        Nr(   )rJ   r   r   s      r*   debugzScreen.debug'  r  r)   )rL   r7   )rc   r   rd   r   rL   rM   rL   r/   )rL   z	List[str]rL   rM   )NN)rd   Optional[int]rc   r?  rL   rM   )r    r?  r!   r?  rL   rM   )r   r   r   r   rL   rM   )r   r/   r\   r/   rL   rM   )r8   r/   rL   rM   )r   r/   rL   rM   rR   )r   r?  rL   rM   )r   F)r   r   r   r3   rL   rM   r  r   r   r   r   r   r   rL   rM   )r   r   rL   rM   )r   zOptional[bool]rL   rM   )rv   r?  r   r?  rL   rM   )r   r?  rL   rM   )rv   r?  rL   rM   )r   r   rL   rM   )rF   r   rL   rM   )r\   r   r   r3   rL   rM   )r\   r   rL   rM   r   r   r   r   rL   rM   )7r#   r$   r%   r&   propertyr]   rK   ro   r|   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r
  r   r  r   r  r  r  r  r   r5  r9  r2  r<  r(   r)   r*   rX   rX      s5   DJ K K
/B L L&1P'R!#F''R%&N0 A&F#B#2#(#.""$(,(6%$N)" E=?B6$
I.B`7I(r)   rX   c                  $     e Zd ZdZd fdZ xZS )
DiffScreena  
    A screen subclass, which maintains a set of dirty lines in its
    :attr:`dirty` attribute. The end user is responsible for emptying
    a set, when a diff is applied.

    .. deprecated:: 0.7.0

       The functionality contained in this class has been merged into
       :class:`~pyte.screens.Screen` and will be removed in 0.8.0.
       Please update your code accordingly.
    c                `    t        j                  dt               t        t        |   |i | y )NzThe functionality of ``DiffScreen` has been merged into ``Screen`` and will be removed in 0.8.0. Please update your code accordingly.)warningswarnDeprecationWarningsuperrD  rK   )rJ   r   r   rn   s      r*   rK   zDiffScreen.__init__:  s-    %&8	:
 	j$($9&9r)   rA  )r#   r$   r%   r&   rK   __classcell__rn   s   @r*   rD  rD  .  s    
: :r)   rD  c                  @    e Zd ZU ded<   ded<   ded<   ded<   ded<   y	)
Historyz#deque[StaticDefaultDict[int, Char]]r    r!   floatratior   sizepositionN)r#   r$   r%   r'   r(   r)   r*   rM  rM  C  s    	,,//L
IMr)   rM  c                       e Zd ZdZ eej                        Zej                  ddg       dd fdZ	ddZ
d fdZddZddZdd	Zd fd
Zdd fdZd fdZd fdZddZddZ xZS )HistoryScreena!  A :class:`~pyte.screens.Screen` subclass, which keeps track
    of screen history and allows pagination. This is not linux-specific,
    but still useful; see page 462 of VT520 User's Manual.

    :param int history: total number of history lines to keep; is split
                        between top and bottom queues.
    :param int ratio: defines how much lines to scroll on :meth:`next_page`
                      and :meth:`prev_page` calls.

    .. attribute:: history

       A pair of history queues for top and bottom margins accordingly;
       here's the overall screen structure::

            [ 1: .......]
            [ 2: .......]  <- top history
            [ 3: .......]
            ------------
            [ 4: .......]  s
            [ 5: .......]  c
            [ 6: .......]  r
            [ 7: .......]  e
            [ 8: .......]  e
            [ 9: .......]  n
            ------------
            [10: .......]
            [11: .......]  <- bottom history
            [12: .......]

    .. note::

       Don't forget to update :class:`~pyte.streams.Stream` class with
       appropriate escape sequences -- you can use any, since pagination
       protocol is not standardized, for example::

           Stream.escape["N"] = "next_page"
           Stream.escape["P"] = "prev_page"
    	next_page	prev_pagec                    t        t        |      t        |      t        |      ||      | _        t        t
        |   ||       y )N)maxlen)rM  r   rN  historyrI  rS  rK   )rJ   rc   rd   rX  rO  rn   s        r*   rK   zHistoryScreen.__init__u  s>    uG4$G4$U|&&	( 	mT+GU;r)   c                     d fd}|S )Nc                 \    j                          | i |}j                         |S rR   )before_eventafter_event)r   r   resulteventhandlerrJ   s      r*   innerz*HistoryScreen._make_wrapper.<locals>.inner  s3    e$d-f-FU#Mr)   )r   r   r   r   rL   r   r(   )rJ   r^  r_  r`  s   ``` r*   _make_wrapperzHistoryScreen._make_wrapper~  s    	
 r)   c                    t         t        |   |      }|t        j                  v rt        j	                  | ||      S |S rR   )rI  rS  __getattribute___wrappedra  )rJ   r-  valuern   s      r*   rc  zHistoryScreen.__getattribute__  s<    mT;DA=))) ..tT5AALr)   c                    |dvrm| j                   j                  | j                   j                  k  r?| j                          | j                   j                  | j                   j                  k  r>yyy)zEnsure a screen is at the bottom of the history buffer.

        :param str event: event name, for example ``"linefeed"``.
        rU  rT  N)rX  rQ  rP  rT  )rJ   r^  s     r*   r[  zHistoryScreen.before_event  sV    
 22,,''$,,*;*;;  ,,''$,,*;*;; 3r)   c                P   |dv rG| j                   j                         D ]*  }|D ]#  }|| j                  kD  s|j                  |       % , | j                  j
                  | j                  j                  k(  xr t        j                  | j                  v  | j                  _        y)zEnsure all lines on a screen have proper width (:attr:`columns`).

        Extra characters are truncated, missing characters are filled
        with whitespace.

        :param str event: event name, for example ``"linefeed"``.
        rg  N)re   r   rc   r   rX  rQ  rP  rZ   r   r\   r.   rG   )rJ   r^  rv   rD   s       r*   r\  zHistoryScreen.after_event  s     ..**, $ $A4<<'$$ LL!!T\\%6%66 $JJ$))#
r)   c                    | j                   j                  j                          | j                   j                  j                          | j                   j	                  | j                   j
                        | _         y )NrQ  )rX  r    r   r!   r   rP  r`   s    r*   _reset_historyzHistoryScreen._reset_history  sQ     !!#||,,dll6G6G,Hr)   c                J    t         t        |           | j                          y)zOverloaded to reset screen history state: history position
        is reset to bottom of both queues;  queues themselves are
        emptied.
        N)rI  rS  rh   rk  )rJ   rn   s    r*   rh   zHistoryScreen.reset  s    
 	mT(*r)   c                `    t        t        | 
  |g|i | |dk(  r| j                          yy)z"Overloaded to reset history state.r   N)rI  rS  r   rk  )rJ   r   r   r   rn   s       r*   r   zHistoryScreen.erase_in_display  s4    mT3CI$I&I!8! r)   c                   | j                   xs t        d| j                  dz
        \  }}| j                  j                  |k(  r2| j
                  j                  j                  | j                  |          t        t        | /          y)z8Overloaded to update top history with the removed lines.r   r   N)rk   r   rd   r.   rE   rX  r    r   re   rI  rS  r   rJ   r    r!   rn   s      r*   r   zHistoryScreen.index  sb    ll@gaa&@V;;==F"LL##DKK$45mT(*r)   c                   | j                   xs t        d| j                  dz
        \  }}| j                  j                  |k(  r2| j
                  j                  j                  | j                  |          t        t        | /          y)z;Overloaded to update bottom history with the removed lines.r   r   N)rk   r   rd   r.   rE   rX  r!   r   re   rI  rS  r   ro  s      r*   r   zHistoryScreen.reverse_index  sb    ll@gaa&@V;;==CLL&&t{{6':;mT02r)   c           	          j                   j                   j                  kD  r j                   j                  rt	        t         j                   j                        t        t        j                   j                   j                   j                  z                    } j                   j                  j                   fdt         j                  dz
   j                  |z
  dz
  d      D                j                   j                   j                   j                  |z
         _         t         j                  dz
  |dz
  d      D ]!  } j                  ||z
      j                  |<   # t        |dz
  dd      D ]3  } j                   j                  j                          j                  |<   5 t!        t         j                               _        yyy)zMove the screen page up through the history buffer. Page
        size is defined by ``history.ratio``, so for instance
        ``ratio = .5`` means that half the screen is restored from
        history on page switch.
        c              3  <   K   | ]  }j                   |     y wrR   re   .0rE   rJ   s     r*   	<genexpr>z*HistoryScreen.prev_page.<locals>.<genexpr>  s#      +J A+J   r   r   rj  N)rX  rQ  rd   r    r   lenr   mathceilrO  r!   
extendleftrs   r   re   r   rf   rg   rJ   midrE   s   `  r*   rU  zHistoryScreen.prev_page  sw    <<  4::-$,,2B2Bc$,,**+$))DJJ1C1C$CDEGC LL** +JtzzA~tzzC/?!/CRH+J J  <<4<<#8#83#>? L 4::>37B7 6!%QW!5A637B+ 8!%!1!1!5!5!7A8 U4::./DJ 3C-r)   c           	          j                   j                   j                   j                  k  r j                   j                  rt	        t         j                   j                        t        t        j                   j                   j                   j                  z                    } j                   j                  j                   fdt        |      D                j                   j                   j                   j                  |z          _         t         j                  |z
        D ]!  } j                  ||z       j                  |<   # t         j                  |z
   j                        D ]3  } j                   j                  j!                          j                  |<   5 t#        t         j                               _        yyy)z5Move the screen page down through the history buffer.c              3  <   K   | ]  }j                   |     y wrR   rs  rt  s     r*   rv  z*HistoryScreen.next_page.<locals>.<genexpr>  s     #GqDKKN#Grw  rj  N)rX  rQ  rP  r!   r   rx  r   ry  rz  rd   rO  r    extendrs   r   re   popleftrf   rg   r|  s   `  r*   rT  zHistoryScreen.next_page  sT   <<  4<<#4#449L9Lc$,,--.$))DJJ1C1C$CDEGC LL###GE#J#GG<<4<<#8#83#>? L 4::+, 6!%QW!5A64::+TZZ8 ?!%!4!4!<!<!>A? U4::./DJ :M4r)   )d   g      ?)
rc   r   rd   r   rX  r   rO  rN  rL   rM   )r^  r/   r_  Callable[..., Any]rL   r  )r-  r/   rL   r  )r^  r/   rL   rM   r>  r  r@  )r#   r$   r%   r&   rf   r   eventsrd  r   rK   ra  rc  r[  r\  rk  rh   r   r   r   rU  rT  rJ  rK  s   @r*   rS  rS  K  sg    %L 6==!HOO[+./<!
*I
"+30.0r)   rS  c                  R    e Zd ZU dZded<   ded<   ded<   edd       ZddZdd	Zy
)
DebugEventzEvent dispatched to :class:`~pyte.screens.DebugScreen`.

    .. warning::

       This is developer API with no backward compatibility guarantees.
       Use at your own risk!
    r/   namer   r   r   c                8    t        t        j                  |        S rR   )r  jsonloads)rv   s    r*   from_stringzDebugEvent.from_string  s    4::d+,,r)   c                ,    t        j                  |       S rR   )r  dumpsr`   s    r*   __str__zDebugEvent.__str__
  s    zz$r)   c                b     t        || j                        | j                  i | j                  S )z)Execute this event on a given ``screen``.)getattrr  r   r   )rJ   screens     r*   __call__zDebugEvent.__call__  s'    )wvtyy)499DDDr)   N)rv   r/   rL   r  r=  )r  rX   rL   r   )	r#   r$   r%   r&   r'   staticmethodr  r  r  r(   r)   r*   r  r    s5     I
IK- - Er)   r  c                  N     e Zd ZdZej
                  dfddZddZd fdZ xZ	S )DebugScreena  A screen which dumps a subset of the received events to a file.

    >>> import io
    >>> with io.StringIO() as buf:
    ...     stream = Stream(DebugScreen(to=buf))
    ...     stream.feed("\x1b[1;24r\x1b[4l\x1b[24;1H\x1b[0;10m")
    ...     print(buf.getvalue())
    ...
    ... # doctest: +NORMALIZE_WHITESPACE
    ["set_margins", [1, 24], {}]
    ["reset_mode", [4], {}]
    ["cursor_position", [24, 1], {}]
    ["select_graphic_rendition", [0, 10], {}]

    :param file to: a file-like object to write debug information to.
    :param list only: a list of events you want to debug (empty by
                      default, which means -- debug all events).

    .. warning::

       This is developer API with no backward compatibility guarantees.
       Use at your own risk!
    r(   c                     || _         || _        y rR   )toonly)rJ   r  r  s      r*   rK   zDebugScreen.__init__*  s    	r)   c                     d fd}|S )Nc            	         j                   j                  t        t        | |                   j                   j                  t        t        j
                               y rR   )r  writer/   r  oslinesep)r   r   r-  rJ   s     r*   wrapperz)DebugScreen.only_wrapper.<locals>.wrapper/  s9    GGMM#jtV<=>GGMM#bjj/*r)   rA  r(   )rJ   r-  r  s   `` r*   only_wrapperzDebugScreen.only_wrapper.  s    	+ r)   c                    |t         j                  vrt        t        |   |      S | j
                  r|| j
                  v r| j                  |      S d S )Nc                      y rR   r(   )r   r   s     r*   ra   z.DebugScreen.__getattribute__.<locals>.<lambda>;  r  r)   )r   r  rI  r  rc  r  r  )rJ   r-  rn   s     r*   rc  zDebugScreen.__getattribute__5  sJ    v}}$d<TBBddii/$$T**//r)   )r  r   r  zSequence[str]rL   rM   )r-  r/   rL   zCallable[..., None])
r#   r$   r%   r&   sysstderrrK   r  rc  rJ  rK  s   @r*   r  r    s'    . %(JJb 0 0r)   r  );r&   
__future__r   rj   r  ry  r  r  r   rF  collectionsr   r   	functoolsr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   _wcwidthrz   r   r   r   r3  r   r  r   rZ   streamsr   r'   r   r   r   r,   r7   r-   rP   rf   r   r   ri   rX   rD  rM  rS  r  r  r(   r)   r*   <module>r     s  4 #    	 
   *  z z z z '   7	$ 7 A	 AT]T]j 

 : < $RV & RYY

+,_ _D: :*j l0F l0^E E0)0 )0r)   