????
Your IP : 3.147.195.139
3
�ft`f9�@sxddlmZddlmZddlZddlZddlZddlZddlZddl Z ddl
Z
ddd�Zddd�ZGd d
�d
e
�ZdS)
�)�absolute_import)�unicode_literalsN�cCsBy(d}tj|tj|�}tjd|�d}|Stk
r<dSXdS)z Get the real terminal width ZabcdefghshhhhrN)�fcntlZioctl�termiosZ
TIOCGWINSZ�struct�unpack�IOError)�fdZbuf�ret�r�/usr/lib/python3.6/term.py�_real_term_widthsrcCs&tdd�}|sdS|dkrdS|SdS)z@ Compute terminal width falling to default 80 in case of troubler)r
�P�N)r)r
Ztwrrr
�_term_width)s
rc @seZdZdZdZedd��Zedd��Zdddd �Zd
ddd
ddddd�Z d
ddd
ddddd�Z
ddddddd�Zdddddd d!d"d�Zd#d$d%d&d'd(d)d*d�Z
d+d,�ZdFd/d0�ZdGd1d2�Zd3d4�Zd5d6�Zd7d8�ZdHd:d;�Zd<d=�Zd>d?�Zd@dA�ZdBdC�ZdDdE�Zd-S)I�Termz>A class to provide some terminal "UI" helpers based on curses.TcCst�S)N)r)�selfrrr
�<lambda>@sz
Term.<lambda>cCst�S)N)r)rrrr
rAsZsmulZrevZsgr0)� underline�reverse�normalrr������)�black�blue�green�cyan�red�magenta�yellow�white)rr"r r$rr#r!r%z[1mz[5m�z[7mz[4mz(B[m)�bold�blink�dimrrrz[30mz[31mz[32mz[33mz[34mz[35mz[36mz[37mz[40mz[41mz[42mz[43mz[44mz[45mz[46mz[47mcCs|j|_|j|_|j|_dS)N)�_Term__ansi_forced_MODE�MODE�_Term__ansi_forced_FG_COLOR�FG_COLOR�_Term__ansi_forced_BG_COLOR�BG_COLOR)rrrr
Z
__forced_initzszTerm.__forced_initN�autocCsLd|_d|_|dkr |j�dSddddddd�|_ddddddddd�|_ddddddddd�|_|dkrvd |_dS|s�tj}|j�s�d |_dSyt j
|j�d
�Wntk
r�d |_dSXt j
|_t jd�|_x8|jD].}|}||jk�r�|j|}|j|�|j|<q�W|jd�jd
�}|�r\x4|jj�D]&\}}t j||�j��pNd|j|<�q2W|jd�jd
�}|�r�x8|jj�D]*\}}t j||�j��p�d}||j|<�q~W|jd�jd
�} | �r�x4|jj�D]&\}}t j| |�j��p�d|j|<�q�W|jd�jd
�}
|
�rHx8|jj�D]*\}}t j|
|�j��p6d}||j|<�qWdS)a
Reinitializes the :class:`Term`.
:param term_stream: the terminal stream that the
:class:`Term` should be initialized to use. If
*term_stream* is not given, :attr:`sys.stdout` is used.
:param color: when to colorize output. Valid values are
'always', 'auto', and 'never'. 'always' will use ANSI codes
to always colorize output, 'auto' will decide whether do
colorize depending on the terminal, and 'never' will never
colorize.
T��alwaysNr&)r'r(r)rrr)rrr r!r"r#r$r%ZneverF)r
�linesZsetfzutf-8ZsetafZsetbZsetab)�_Term__enabledr3�_Term__forced_initr+r-r/�sys�stdout�isatty�cursesZ setupterm�fileno� ExceptionZtigetstr�
_ctigetstrZtigetnum�_Term__cap_names� _tigetstr�encode�
_Term__colors�itemsZtparm�decode�_Term__ansi_colors)r�term_stream�color�cap_name�modeZset_fg�valZset_fg_ansiZfg_colorZset_bgZset_bg_ansiZbg_colorrrr
�reinits�
""zTerm.reinitcCs|j||�dS)N)rI)rrDrErrr
�__init__�sz
Term.__init__cCs0|j|�pd}tjj|�r"|j�}tjdd|�S)Nr&z\$<\d+>[/*]?)r<�dnfZpycompZis_py3bytesrB�re�sub)rrFZcaprrr
r>�szTerm._tigetstrcCs|j|t|�|jdS)zColorize string with colorr)r+�str)rrE�srrr
rE�sz
Term.colorcCs|jd|�S)zMake string bold.r')rE)rrOrrr
r'�sz Term.boldFc
s\|js
|S|stj}��fdd�}x4|D],}||�} |rFtj| tj�} tj| ||�}q(W|S)aSearch the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
*beg*, and postfix each occurrence with *end*, then return the
modified string. For example::
>>> yt = Term()
>>> yt.sub('spam and eggs', 'x', 'z', ['and'])
'spam xandz eggs'
This is particularly useful for emphasizing certain words
in output: for example, calling :func:`sub` with *beg* =
MODE['bold'] and *end* = MODE['normal'] will return a string
that when printed to the terminal will appear to be *haystack*
with each occurrence of the strings in *needles* in bold
face. Note, however, that the :func:`sub_mode`,
:func:`sub_bold`, :func:`sub_fg`, and :func:`sub_bg` methods
provide convenient ways to access this same emphasizing functionality.
:param haystack: the string to be modified
:param beg: the string to be prefixed onto matches
:param end: the string to be postfixed onto matches
:param needles: a list of strings to add the prefixes and
postfixes to
:param escape: a function that accepts a string and returns
the same string with problematic characters escaped. By
default, :func:`re.escape` is used.
:param ignore_case: whether case should be ignored when
searching for matches
:return: *haystack* with *beg* prefixing, and *end*
postfixing, occurrences of the strings in *needles*
cs�|j��S)N)�group)�match)�beg�endrr
rszTerm.sub.<locals>.<lambda>)r4rL�escape�template�IrM)
r�haystackrRrS�needlesrTZignore_caseZrenderZneedleZpatr)rRrSr
rM�s
zTerm.subcKs|j|||jd|f|�S)aOSearch the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
*beg*, and postfix each occurrence with self.MODE['normal'],
then return the modified string. If *beg* is an ANSI escape
code, such as given by self.MODE['bold'], this method will
return *haystack* with the formatting given by the code only
applied to the strings in *needles*.
:param haystack: the string to be modified
:param beg: the string to be prefixed onto matches
:param end: the string to be postfixed onto matches
:param needles: a list of strings to add the prefixes and
postfixes to
:return: *haystack* with *beg* prefixing, and self.MODE['normal']
postfixing, occurrences of the strings in *needles*
r)rMr+)rrWrRrX�kwdsrrr
�sub_norm&sz
Term.sub_normcKs|j||j||f|�S)aTSearch the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
self.MODE[*mode*], and postfix each occurrence with
self.MODE['normal'], then return the modified string. This
will return a string that when printed to the terminal will
appear to be *haystack* with each occurrence of the strings in
*needles* in the given *mode*.
:param haystack: the string to be modified
:param mode: the mode to set the matches to be in. Valid
values are given by self.MODE.keys().
:param needles: a list of strings to add the prefixes and
postfixes to
:return: *haystack* with self.MODE[*mode*] prefixing, and
self.MODE['normal'] postfixing, occurrences of the strings
in *needles*
)rZr+)rrWrGrXrYrrr
�sub_mode9sz
Term.sub_modecKs|j|d|f|�S)a�Search the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
self.MODE['bold'], and postfix each occurrence with
self.MODE['normal'], then return the modified string. This
will return a string that when printed to the terminal will
appear to be *haystack* with each occurrence of the strings in
*needles* in bold face.
:param haystack: the string to be modified
:param needles: a list of strings to add the prefixes and
postfixes to
:return: *haystack* with self.MODE['bold'] prefixing, and
self.MODE['normal'] postfixing, occurrences of the strings
in *needles*
r')r[)rrWrXrYrrr
�sub_boldMsz
Term.sub_boldcKs|j||j||f|�S)acSearch the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
self.FG_COLOR[*color*], and postfix each occurrence with
self.MODE['normal'], then return the modified string. This
will return a string that when printed to the terminal will
appear to be *haystack* with each occurrence of the strings in
*needles* in the given color.
:param haystack: the string to be modified
:param color: the color to set the matches to be in. Valid
values are given by self.FG_COLOR.keys().
:param needles: a list of strings to add the prefixes and
postfixes to
:return: *haystack* with self.FG_COLOR[*color*] prefixing, and
self.MODE['normal'] postfixing, occurrences of the strings
in *needles*
)rZr-)rrWrErXrYrrr
�sub_fg_szTerm.sub_fgcKs|j||j||f|�S)a�Search the string *haystack* for all occurrences of any
string in the list *needles*. Prefix each occurrence with
self.BG_COLOR[*color*], and postfix each occurrence with
self.MODE['normal'], then return the modified string. This
will return a string that when printed to the terminal will
appear to be *haystack* with each occurrence of the strings in
*needles* highlighted in the given background color.
:param haystack: the string to be modified
:param color: the background color to set the matches to be in. Valid
values are given by self.BG_COLOR.keys().
:param needles: a list of strings to add the prefixes and
postfixes to
:return: *haystack* with self.BG_COLOR[*color*] prefixing, and
self.MODE['normal'] postfixing, occurrences of the strings
in *needles*
)rZr/)rrWrErXrYrrr
�sub_bgsszTerm.sub_bg)Nr0)Nr0)NF)�__name__�
__module__�__qualname__�__doc__r4�propertyZreal_columns�columnsr=r@rCr*r,r.r5rIrJr>rEr'rMrZr[r\r]r^rrrr
r4sr
f
-r)r)r)Z
__future__rrr9Z
dnf.pycomprKrrLrr6rrr�objectrrrrr
�<module>s