
    jj1                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ dd	lmZmZmZ dd
lmZmZ ej*                  rd dlmZ d dlmZ d dlmZ  G d de      Z G d de      Zy)    )annotationsN)text_layout)apply_text_layout)remove_defaults)
calc_width)decompose_tagmarkupget_encoding   )AlignSizingWrapMode)WidgetWidgetError)Hashable)Literal)
TextCanvasc                      e Zd Zy)	TextErrorN)__name__
__module____qualname__     Z/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/text.pyr   r      s    r   r   c                      e Zd ZdZ eej                  ej                  g      ZdZ	dZ
ej                  ej                  df	 	 	 	 	 	 	 	 	 d fdZd fdZd fdZd fdZdd	Zdd
Zedd       Zedd       Zd dZd!dZ	 d"	 	 	 	 	 	 	 d#dZ ed e      Z ed e      Zed        Z	 d$	 	 	 	 	 d%dZd$d&dZ	 d"	 	 	 	 	 d'dZ 	 	 	 	 	 	 d(dZ!	 	 d)	 	 	 	 	 d*dZ" xZ#S )+Textz/
    a horizontally resizeable text widget
    T   Nc                    t         |           d| _        |xs t        j                  | _        | j                  |       | j                  |||       y)ae  
        :param markup: content of text widget, one of:

            bytes or unicode
              text to be displayed

            (*display attribute*, *text markup*)
              *text markup* with *display attribute* applied to all parts
              of *text markup* with no display attribute already applied

            [*text markup*, *text markup*, ... ]
              all *text markup* in the list joined together

        :type markup: :ref:`text-markup`
        :param align: typically ``'left'``, ``'center'`` or ``'right'``
        :type align: text alignment mode
        :param wrap: typically ``'space'``, ``'any'``, ``'clip'`` or ``'ellipsis'``
        :type wrap: text wrapping mode
        :param layout: defaults to a shared :class:`StandardTextLayout` instance
        :type layout: text layout instance

        >>> Text("Hello")
        <Text fixed/flow widget 'Hello'>
        >>> t = Text(("bold", "stuff"), "right", "any")
        >>> t
        <Text fixed/flow widget 'stuff' align='right' wrap='any'>
        >>> print(t.text)
        stuff
        >>> t.attrib
        [('bold', 5)]
        N)super__init___cache_maxcolr   default_layout_layoutset_text
set_layout)selfmarkupalignwraplayout	__class__s        r   r    zText.__init__$   sG    L 	)-/5/S9S9SftV,r   c                    t         |          }| j                         d   }t        |      }t	        |      | j
                  kD  r/|d| j
                  dz  dz  dz
   dz   || j
                   dz  d z   }g ||S )zw
        Show the text in the repr in python3 format (b prefix for byte strings) and truncate if it's too long
        r   N      z...)r   _repr_wordsget_textreprlen_repr_content_length_max)r&   firsttextrestr+   s       r   r/   zText._repr_wordsP   s     #%}}q!Dzt9t444At44q8A=ABUJTSWSpSpRptuRuRwMxx  ~~r   c                    i t         |          | j                  | j                  d}t	        |t
        j                        S )N)r(   r)   )r   _repr_attrs_align_mode
_wrap_moder   r   r    )r&   attrsr+   s     r   r8   zText._repr_attrs]   sB    
g!#
%%OO

 udmm44r   c                0    d | _         t        | 	          y N)r!   r   _invalidate)r&   r+   s    r   r>   zText._invalidatee   s    !r   c                T    t        |      \  | _        | _        | j                          y)a  
        Set content of text widget.

        :param markup: see :class:`Text` for description.
        :type markup: text markup

        >>> t = Text("foo")
        >>> print(t.text)
        foo
        >>> t.set_text("bar")
        >>> print(t.text)
        bar
        >>> t.text = "baz"  # not supported because text stores text but set_text() takes markup
        Traceback (most recent call last):
        AttributeError: can't set attribute
        N)r   _text_attribr>   )r&   r'   s     r   r$   zText.set_texti   s#    " $7v#> 
DLr   c                2    | j                   | j                  fS )aR  
        :returns: (*text*, *display attributes*)

            *text*
              complete bytes/unicode content of text widget

            *display attributes*
              run length encoded display attributes for *text*, eg.
              ``[('attr1', 10), ('attr2', 5)]``

        >>> Text("Hello").get_text()  # ... = u in Python 2
        (...'Hello', [])
        >>> Text(("bright", "Headline")).get_text()
        (...'Headline', [('bright', 8)])
        >>> Text([("a", "one"), "two", ("b", "three")]).get_text()
        (...'onetwothree', [('a', 3), (None, 3), ('b', 5)])
        )r@   rA   r&   s    r   r0   zText.get_text}   s    $ zz4<<''r   c                (    | j                         d   S )zh
        Read-only property returning the complete bytes/unicode content
        of this widget
        r   r0   rC   s    r   r5   z	Text.text        }}q!!r   c                (    | j                         d   S )zo
        Read-only property returning the run-length encoded display
        attributes of this widget
        r
   rE   rC   s    r   attribzText.attrib   rF   r   c                    | j                   j                  |      st        d|d      || _        | j	                          y)a  
        Set text alignment mode. Supported modes depend on text layout
        object in use but defaults to a :class:`StandardTextLayout` instance

        :param mode: typically ``'left'``, ``'center'`` or ``'right'``
        :type mode: text alignment mode

        >>> t = Text("word")
        >>> t.set_align_mode("right")
        >>> t.align
        'right'
        >>> t.render((10,)).text  # ... = b in Python 3
        [...'      word']
        >>> t.align = "center"
        >>> t.render((10,)).text
        [...'   word   ']
        >>> t.align = "somewhere"
        Traceback (most recent call last):
        TextError: Alignment mode 'somewhere' not supported.
        zAlignment mode  not supported.N)r*   supports_align_moder   r9   r>   r&   modes     r   set_align_modezText.set_align_mode   s>    * {{..t4odX_EFFr   c                    | j                   j                  |      st        d|d      || _        | j	                          y)a  
        Set text wrapping mode. Supported modes depend on text layout
        object in use but defaults to a :class:`StandardTextLayout` instance

        :param mode: typically ``'space'``, ``'any'``, ``'clip'`` or ``'ellipsis'``
        :type mode: text wrapping mode

        >>> t = Text("some words")
        >>> t.render((6,)).text  # ... = b in Python 3
        [...'some  ', ...'words ']
        >>> t.set_wrap_mode("clip")
        >>> t.wrap
        'clip'
        >>> t.render((6,)).text
        [...'some w']
        >>> t.wrap = "any"  # Urwid 0.9.9 or later
        >>> t.render((6,)).text
        [...'some w', ...'ords  ']
        >>> t.wrap = "somehow"
        Traceback (most recent call last):
        TextError: Wrap mode 'somehow' not supported.
        z
Wrap mode rJ   N)r*   supports_wrap_moder   r:   r>   rL   s     r   set_wrap_modezText.set_wrap_mode   s=    . {{--d3j@AAr   c                z    |t         j                  }|| _        | j                  |       | j	                  |       y)a	  
        Set the text layout object, alignment and wrapping modes at
        the same time.

        :type align: text alignment mode
        :param wrap: typically 'space', 'any', 'clip' or 'ellipsis'
        :type wrap: text wrapping mode
        :param layout: defaults to a shared :class:`StandardTextLayout` instance
        :type layout: text layout instance

        >>> t = Text("hi")
        >>> t.set_layout("right", "clip")
        >>> t
        <Text fixed/flow widget 'hi' align='right' wrap='clip'>
        N)r   r"   r#   rN   rQ   )r&   r(   r)   r*   s       r   r%   zText.set_layout   s7    * > //FE"4 r   c                    | j                   S r=   )r9   rC   s    r   <lambda>zText.<lambda>   s    $"2"2 r   c                    | j                   S r=   )r:   rC   s    r   rT   zText.<lambda>   s
     r   c                    | j                   S r=   )r#   rC   s    r   r*   zText.layout   s    ||r   c                    | j                         \  }}|r|\  }n| j                  |      \  }}| j                  |||f      }t        ||||      S )a  
        Render contents with wrapping and alignment.  Return canvas.

        See :meth:`Widget.render` for parameter details.

        >>> Text("important things").render((18,)).text
        [b'important things  ']
        >>> Text("important things").render((11,)).text
        [b'important  ', b'things     ']
        >>> Text("demo text").render(()).text
        [b'demo text']
        )focus)r0   packget_line_translationr   )r&   sizerX   r5   attrmaxcol_transs           r   renderzText.render   sX    " ]]_
dIV			.IFA))&4,? tUF;;r   c                >    |\  }t        | j                  |            S )z
        Return the number of rows the rendered text requires.

        See :meth:`Widget.rows` for parameter details.

        >>> Text("important things").rows((18,))
        1
        >>> Text("important things").rows((11,))
        2
        )r2   rZ   )r&   r[   rX   r]   s       r   rowsz	Text.rows  s!     	4,,V455r   c                t    | j                   r| j                   |k7  r| j                  ||       | j                  S )a  
        Return layout structure used to map self.text to a canvas.
        This method is used internally, but may be useful for debugging custom layout classes.

        :param maxcol: columns available for display
        :type maxcol: int
        :param ta: ``None`` or the (*text*, *display attributes*) tuple
                   returned from :meth:`.get_text`
        :type ta: text and display attributes
        )r!   _update_cache_translation_cache_translation)r&   r]   tas      r   rZ   zText.get_line_translation!  s6     !!T%7%76%A**626&&&r   c                    |r|\  }}n| j                         \  }}|| _        | j                  j                  ||| j                  | j                        | _        y r=   )r0   r!   r*   r9   r:   re   )r&   r]   rf   r5   _attrs        r   rd   zText._update_cache_translation4  sQ    
 KD%--/KD%#"&++"4"4T64CSCSUYUdUd"er   c                   | j                         \  }}|rk|\  }t        | j                  d      s|| j                  ||      fS | j	                  |||f      }| j                  j                  ||      }|t        |      fS |rWt        |t              r|j                  t                     }|j                  d      }t        d |D              t        |      fS y)u  
        Return the number of screen columns and rows required for
        this Text widget to be displayed without wrapping or
        clipping, as a single element tuple.

        :param size: ``None`` or ``()`` for unlimited screen columns (like FIXED sizing)
                     or (*maxcol*,) to specify a maximum column size
        :type size: widget size
        :param focus: widget is focused on
        :type focus: bool

        >>> Text("important things").pack()
        (16, 1)
        >>> Text("important things").pack((15,))
        (9, 2)
        >>> Text("important things").pack((8,))
        (8, 2)
        >>> Text("important things").pack(())
        (16, 1)
        >>> not_common_separated_text = "Line feed\nLine Separator\u2028Paragraph Separator\u2029"
        >>> #   (Line Separator) and   (Paragraph Separator) are not splitted by StandardTextLayout
        >>> not_common_separated = Text(not_common_separated_text)

        >>> not_common_separated.pack()
        (33, 2)
        >>> not_common_separated_canv = not_common_separated.render(())
        >>> not_common_separated_canv.cols()
        33
        >>> not_common_separated_canv.rows()
        2
        rY   
c              3  H   K   | ]  }t        |d t        |              yw)r   N)r   r2   ).0lines     r   	<genexpr>zText.pack.<locals>.<genexpr>v  s     JtJtQD	2Js    ")r   r
   )r0   hasattrr*   rb   rZ   rY   r2   
isinstancebytesdecoder	   splitmax)	r&   r[   rX   r5   r\   r]   r_   cols
split_texts	            r   rY   z	Text.pack@  s    H ]]_
dIV4;;/tyyu555--ftTlCE;;##FE2D#e*%%$&{{<>2D)J JzJJJ  r   )
r'   =str | tuple[Hashable, str] | list[str | tuple[Hashable, str]]r(   *Literal['left', 'center', 'right'] | Alignr)   6Literal['space', 'any', 'clip', 'ellipsis'] | WrapModer*   text_layout.TextLayout | NonereturnNone)r{   z	list[str])r{   zdict[str, typing.Any])r{   r|   )r'   rw   r{   r|   )r{   z.tuple[str | bytes, list[tuple[Hashable, int]]])r{   zstr | bytes)r{   zlist[tuple[Hashable, int]])rM   rx   r{   r|   )rM   ry   r{   r|   r=   )r(   rx   r)   ry   r*   rz   r{   r|   )F)r[   ztuple[int] | tuple[()]rX   boolr{   r   )r[   z
tuple[int]rX   r}   r{   int)r]   r~   rf   5tuple[str | bytes, list[tuple[Hashable, int]]] | Noner{   zAlist[list[tuple[int, int, int | bytes] | tuple[int, int | None]]])r]   r~   rf   r   r{   r|   )NF)r[   ztuple[()] | tuple[int] | NonerX   r}   r{   ztuple[int, int])$r   r   r   __doc__	frozensetr   FLOWFIXED_sizingignore_focusr3   r   LEFTr   SPACEr    r/   r8   r>   r$   r0   propertyr5   rH   rN   rQ   r%   r(   r)   r*   r`   rb   rZ   rd   rY   __classcell__)r+   s   @r   r   r      s    fll34GL"
 =BJJGO~~04*-M*- :*- E	*-
 .*- 
*-X5((( " " " "4@ 15	!9! E! .	!
 
!6 2NCE0-@D  <$< < 
	<46" EI'' B' 
K	'&
f
f B
f 
	
f /39+9 9 
	9r   r   )
__future__r   typingurwidr   urwid.canvasr   urwid.split_reprr   urwid.str_utilr   
urwid.utilr   r	   	constantsr   r   r   widgetr   r   TYPE_CHECKINGcollections.abcr   typing_extensionsr   r   r   r   r   r   r   <module>r      sO    "   * , % 8 . . '	()'	 	_6 _r   