o
    ñu]¦  ã                   @   sº   d Z ddlZddlZdZdZejjjeŽ Z	ejjjdd„ eD ƒŽ Z
ejj ddd	d
d¡Zedd„ edƒD ƒƒZedd„ edƒD ƒƒZejdejdejdiZdZed Zdd„ Zdd„ ZdS )añ  
Utilities for working with the terminal.

**Module Overview:**

::

  encoding - provides the ANSI escape sequence for a terminal attribute
  format - wrap text with ANSI for the given colors or attributes

.. data:: Color (enum)
.. data:: BgColor (enum)

  Foreground or background terminal colors.

  =========== ===========
  Color       Description
  =========== ===========
  **BLACK**   black color
  **BLUE**    blue color
  **CYAN**    cyan color
  **GREEN**   green color
  **MAGENTA** magenta color
  **RED**     red color
  **WHITE**   white color
  **YELLOW**  yellow color
  =========== ===========

.. data:: Attr (enum)

  Terminal text attributes.

  .. versionchanged:: 1.5.0
     Added the LINES attribute.

  =================== ===========
  Attr                Description
  =================== ===========
  **BOLD**            heavy typeface
  **HIGHLIGHT**       inverted foreground and background
  **UNDERLINE**       underlined text
  **READLINE_ESCAPE** wrap encodings in `RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE sequences <https://stackoverflow.com/questions/9468435/look-how-to-fix-column-calculation-in-python-readline-if-use-color-prompt>`_
  **LINES**           formats lines individually
  =================== ===========
é    N)ZBLACKZREDZGREENZYELLOWZBLUEZMAGENTAZCYANZWHITEFc                 C   s   g | ]}d | ‘qS )ZBG_© )Ú.0Zcolorr   r   ú0/usr/lib/python3/dist-packages/stem/util/term.pyÚ
<listcomp>=   s    r   ÚBOLDÚ	UNDERLINEÚ	HIGHLIGHTÚREADLINE_ESCAPEÚLINESc                 C   ó$   g | ]}t tƒ| td | ƒf‘qS )é   )ÚlistÚColorÚstr©r   Úir   r   r   r   A   ó   $ é   c                 C   r   )é(   )r   ÚBgColorr   r   r   r   r   r   B   r   Ú1Ú4Ú7z[%smÚ0c                  G   sp   g }| D ](}|dkrd}t jj |¡}t |d¡}t ||¡}t ||¡}|r,| |¡ q|r6t	d 
|¡ S dS )ai  
  Provides the ANSI escape sequence for these terminal color or attributes.

  .. versionadded:: 1.5.0

  :param list attr: :data:`~stem.util.terminal.Color`,
    :data:`~stem.util.terminal.BgColor`, or :data:`~stem.util.terminal.Attr` to
    provide an ecoding for

  :returns: **str** of the ANSI escape sequence, **None** no attributes are
    recognized
  ZHILIGHTr   Nú;)ÚstemÚutilÚ	str_toolsZ_to_camel_caseÚFG_ENCODINGÚgetÚBG_ENCODINGÚATTR_ENCODINGÚappendÚCSIÚjoin)ZattrsZterm_encodingsÚattrZterm_encodingr   r   r   ÚencodingI   s   
€ÿr&   c                    s¸   t jj | ¡} tr| S tjˆ v r+tˆ ƒ‰ ˆ  tj¡ ‡ fdd„|  	d¡D ƒ}d 
|¡S t| v r>d 
‡ fdd„|  	t¡D ƒ¡S tˆ Ž t}}|rZtjˆ v rTd| }d| }||  | S | S )a‘  
  Simple terminal text formatting using `ANSI escape sequences
  <https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes>`_.
  The following are some toolkits providing similar capabilities:

  * `django.utils.termcolors <https://github.com/django/django/blob/master/django/utils/termcolors.py>`_
  * `termcolor <https://pypi.org/project/termcolor/>`_
  * `colorama <https://pypi.org/project/colorama/>`_

  .. versionchanged:: 1.6.0
     Normalized return value to be unicode to better support python 2/3
     compatibility.

  :param str msg: string to be formatted
  :param str attr: text attributes, this can be :data:`~stem.util.term.Color`,
    :data:`~stem.util.term.BgColor`, or :data:`~stem.util.term.Attr` enums
    and are case insensitive (so strings like 'red' are fine)

  :returns: **unicode** wrapped with ANSI escape encodings, starting with the given
    attributes and ending with a reset
  c                    ó   g | ]
}t |gˆ ¢R Ž ‘qS r   ©Úformat)r   Úline©r%   r   r   r   ‹   ó    zformat.<locals>.<listcomp>Ú
Ú c                    r'   r   r(   )r   Úcompr+   r   r   r   ’   r,   z%s)r   r   r   Z_to_unicodeÚDISABLE_COLOR_SUPPORTÚAttrr
   r   ÚremoveÚsplitr$   ÚRESETr&   r	   )Úmsgr%   ÚlinesÚprefixÚsuffixr   r+   r   r)   l   s"   


r)   )Ú__doc__Zstem.util.enumr   Zstem.util.str_toolsZTERM_COLORSr0   r   ÚenumÚEnumr   r   r1   ÚdictÚranger   r    r   r   r   r!   r#   r4   r&   r)   r   r   r   r   Ú<module>   s   .#