Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sgr_state.cpython-313.pyc160 linesDownload Raw Back to __pycache__
1�

2��j�0��$�SrSSKJr SSKrSSKJr SSKJrJrJ	r	 \(aSSKJ3r4 "SS\5r\R"S	5r
\R"S55rSr"SS
\	5r\"5rSSjrSSjrSSjrSSjrSSjrSSjrg)as6SGR (Select Graphic Rendition) state tracking for terminal escape sequences.7 8This module provides functions for tracking and propagating terminal styling (bold, italic, colors,9etc.) via public API propagate_sgr(), and its dependent functions, cut() and wrap(). It only has10attributes necessary to perform its functions, eg 'RED' and 'BLUE' attributes are not defined.11�)�annotationsN)�IntEnum)�
TYPE_CHECKING�Iterator�12NamedTuple)�Sequencec��\rSrSrSrSrSrSrSrSr	Sr13S	rS14rSr
SrSrS
rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!Sr"S r#g!)"�_SGR�z�15SGR (Select Graphic Rendition) parameter codes.16 17References:18- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html19- https://github.com/tehmaze/ansi/tree/master/ansi/colour20r���������	���������%�&�'�(�/�0�1�Z�a�d�k�N)$�__name__�21__module__�__qualname__�__firstlineno__�__doc__�RESET�BOLD�DIM�ITALIC�	UNDERLINE�BLINK�RAPID_BLINK�INVERSE�HIDDEN�
STRIKETHROUGH�DOUBLE_UNDERLINE�BOLD_DIM_OFF�22ITALIC_OFF�
UNDERLINE_OFF�	BLINK_OFF�INVERSE_OFF�23HIDDEN_OFF�STRIKETHROUGH_OFF�FG_BLACK�FG_WHITE�FG_EXTENDED�24FG_DEFAULT�BG_BLACK�BG_WHITE�BG_EXTENDED�25BG_DEFAULT�FG_BRIGHT_BLACK�FG_BRIGHT_WHITE�BG_BRIGHT_BLACK�BG_BRIGHT_WHITE�__static_attributes__r(��WD:\code\apps\devtools\python\user_packages\Python313\site-packages\wcwidth/sgr_state.pyr26r27s����
�E��D�28�C�
�F��I�
�E��K��G�
�F��M����L��J��M��I��K��J����H��H��K��J��H��H��K��J��O��O��O��OrMr29z\x1b\[([\d;:]*)mz\x1b\[[\d;:]*mzc���\rSrSr%SrSrS\S'SrS\S'SrS\S'Sr	S\S'Sr30S\S	'SrS\S31'SrS\S'Sr
S\S'SrS\S
'SrS\S'SrS\S'SrS\S'Srg)�	_SGRState�Ka�32Track active SGR terminal attributes by category (immutable).33 34:param bold: Bold attribute (SGR 1).35:param dim: Dim/faint attribute (SGR 2).36:param italic: Italic attribute (SGR 3).37:param underline: Underline attribute (SGR 4).38:param blink: Slow blink attribute (SGR 5).39:param rapid_blink: Rapid blink attribute (SGR 6).40:param inverse: Inverse/reverse attribute (SGR 7).41:param hidden: Hidden/invisible attribute (SGR 8).42:param strikethrough: Strikethrough attribute (SGR 9).43:param double_underline: Double underline attribute (SGR 21).44:param foreground: Foreground color as tuple of SGR params, or None for default.45:param background: Background color as tuple of SGR params, or None for default.46F�bool�bold�dim�italic�	underline�blink�rapid_blink�inverse�hidden�
strikethrough�double_underlineN�tuple[int, ...] | None�47foreground�48backgroundr()r)r*r+r,r-rS�__annotations__rTrUrVrWrXrYrZr[r\r^r_rLr(rMrNrPrPKs����"�D�$���C����F�D���I�t���E�4���K����G�T���F�D���M�4��"��d�"�)-�J�&�-�)-�J�&�-rMrPc���UR=(d� UR=(d� UR=(d� UR=(d� UR=(d� UR49=(do UR=(d\ UR=(dI UR=(d6 UR=(d# URSL=(d URSL$)z�50Return True if any attributes are set.51 52:param state: The SGR state to check.53:returns: True if any attribute differs from default.54N)rSrTrUrVrWrXrYrZr[r\r^r_)�states rN�_sgr_state_is_activercos���
�J�J�
L�%�)�)�
L�u�|�|�
L�u���
L��{�{�
L�#�/�/�
L�38�=�=�
L�DI�L�L�
L��"�"�
L�&+�&<�&<�
L����t�+�
L�05�/?�/?�t�/K�MrMc��[U5(dgURS4URS4URS4URS4UR55S4URS4URS4URS	4URS564URS4/57nUVVs/sHup#U(dMUPM nnnURb1URSRS
UR555 URb1URSRSUR555 SSRU5S3$s snnf)z�58Generate minimal SGR sequence to restore this state from reset.59 60:param state: The SGR state to convert.61:returns: SGR escape sequence string, or empty string if no attributes set.62��1�2�3�4�5�6�7�8�9�21�;c3�8# �UHn[U5v� M g7f�N��str��.0�ps  rN�	<genexpr>�)_sgr_state_to_sequence.<locals>.<genexpr>�����@�/?�!�s�1�v�v�/?���c3�8# �UHn[U5v� M g7frrrsrus  rNrxry�rzr{z[�m)rcrSrTrUrVrWrXrYrZr[r\r^�append�joinr_)rb�63bool_attrs�active�code�paramss     rN�_sgr_state_to_sequencer�|s'�� ��&�&��64���S��E�I�I�s�+�e�l�l�C�-@�	���#�����c� 2�U�5F�5F��4L�	�����u�|�|�S�1�E�4G�4G��3M�	�	�	��&�	�J�(2�
<�z�|�v�V�d�z�F�
<�
���#��
�
�c�h�h�@�u�/?�/?�@�@�A����#��
�
�c�h�h�@�u�/?�/?�@�@�A�
�3�8�8�F�#�$�A�&�&��=s�
E�,Ec��[RU5nU(d/$URS5nU(dS/$/nURS5HznSU;aNURS5Vs/sHoU(a[	U5OSPM nnUR[
U55 MWURU(a[	U5OS5 M| U$s snf)a�65Parse SGR sequence and return list of parameter values.66 67Handles compound sequences like ``\x1b[1;31;4m`` -> [1, 31, 4].68Empty params (e.g., ``\x1b[m``) are treated as [0] (reset).69Colon-separated extended colors like ``\x1b[38:2::255:0:0m`` are returned70as tuples: [(38, 2, 255, 0, 0)].71 72:param sequence: SGR escape sequence string.73:returns: List of integer parameters or tuples for colon-separated colors.74rrrp�:)�_SGR_PATTERN�match�group�split�intr~�tuple)�sequencer��75params_str�result�paramrw�partss       rN�_parse_sgr_paramsr��s���
���x�(�E���	����Q��J���s�76�*,�F��!�!�#�&���%�<�27���S�1A�B�1A�A�q�S��V�a�'�1A�E�B��M�M�%��,�'��M�M��#�e�*�1�5�'��M��	Cs�)C
c��[U5n[U[5(agUS:Xa/[U5n[U[5(ag[U5SU4$US:Xao[U5[U5[U5pen[U[5(d*[U[5(d[U[5(ag[U5SXEU4$g![a gf=f)a%77Parse extended color (256-color or RGB) from parameter iterator.78 79:param params: Iterator of remaining SGR parameters (semicolon-separated format).80:param base: Base code (38 for foreground, 48 for background).81:returns: Color tuple like (38, 5, N) or (38, 2, R, G, B), or None if malformed.82Nrr
)�next�83isinstancer�r��
StopIteration)r��base�mode�n�r�g�bs       rN�_parse_extended_colorr��s���
��F�|���d�E�"�"���1�9��V��A��!�U�#�#����I�q�!�$�$��1�9��6�l�D��L�$�v�,�!�A��!�U�#�#�z�!�U�';�';�z�!�U�?S�?S����I�q�!��*�*�	����
���
�s)� C�&C�84
C�A%C�>C�85C�Cc��	�[U5n[U5nUGH�n[U[5(am[	U5S:�a'US[86R:XaURUS9nO5[	U5S:�a&US[87R:XaURUS9nM�U[88R:Xa[nM�U[89R:XaURSS9nM�U[90R:XaURSS9nM�U[91R:XaURSS9nGMU[92R:XaURSS	9nGM8U[93R:XaURSS949nGM^U[95R :XaURSS9nGM�U[96R":XaURSS9nGM�U[97R$:XaURSS
9nGM�U[98R&:XaURSS9nGM�U[99R(:XaURSS9nGMU[100R*:XaURSSS9nGMCU[101R,:XaURSS9nGMiU[102R.:XaURSSS9nGM�U[103R0:XaURSSS9nGM�U[104R2:XaURSS9nGM�U[105R4:XaURSS
9nGMU[106R6:XaURSS9nGM)[107R8Us=::a[108R:::d.O [109R<Us=::a[110R>::aO OURU4S9nGM�[111R@Us=::a[112RB::d.O [113RDUs=::a[114RF::aO OURU4S9nGM�U[115RH:XaURSS9nGM#U[116RJ:XaURSS9nGMIU[117R:Xa6[MU[118R5=n(aURUS9nGM�GM�U[119R:XdGM�[MU[120R5=n(dGM�URUS9nGM� U$)z�121Parse SGR sequence and return new state with updates applied.122 123:param state: Current SGR state.124:param sequence: SGR escape sequence string.125:returns: New SGRState with updates applied.126r
r)r^)r_T)rS)rT)rU)rV)rW)rX)rY)rZ)r[)r\F)rSrT)rVr\)rWrXN)'r��iterr�r��lenr127rB�_replacerFr.�_SGR_STATE_DEFAULTr/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArHrIrDrErJrKrCrGr�)rbr��params_listr�rw�colors      rN�_sgr_state_updater��s���$�H�-�K�
�+�
�F�
���a�����1�v��{�q��t�t�'7�'7�7����!��4���Q��1���1���)9�)9�!9����!��4�����128�129�?�&�E�
�$�)�)�^��N�N��N�-�E�
�$�(�(�]��N�N�t�N�,�E�
�$�+�+�
��N�N�$�N�/�E�
�$�.�.�
 ��N�N�T�N�2�E�
�$�*�*�_��N�N��N�.�E�
�$�"�"�
"��N�N�t�N�4�E�
�$�,�,�
��N�N�4�N�0�E�
�$�+�+�
��N�N�$�N�/�E�
�$�$�$�
$��N�N��N�6�E�
�$�'�'�
'��N�N�D�N�9�E�
�$�#�#�
#��N�N��5�N�9�E�
�$�/�/�
!��N�N�%�N�0�E�
�$�$�$�
$��N�N�U�U�N�K�E�
�$�.�.�
 ��N�N��E�N�B�E�
�$�"�"�
"��N�N�5�N�1�E�
�$�/�/�
!��N�N�%�N�0�E�
�$�(�(�
(��N�N��N�7�E��m�m�q�1�D�M�M�1��%�%��B�d�.B�.B�B��N�N�q�d�N�3�E��m�m�q�1�D�M�M�1��%�%��B�d�.B�.B�B��N�N�q�d�N�3�E�
�$�/�/�
!��N�N�d�N�3�E�
�$�/�/�
!��N�N�d�N�3�E�
�$�"�"�
"�-�f�d�6F�6F�G�G�u�G����%��8��H�
�$�"�"�
"�-�f�d�6F�6F�G�G�u�G�G����%��8��C�D�LrMc�h�[SU55(aU(d[U5$/n[nUHzn[U5n[RU5Hn[
X%R55nM U(aXC-OUn[U5(a	U[-nURU5 M| U$)a�130Propagate SGR codes across wrapped lines.131 132When text with SGR styling is wrapped across multiple lines, each line133needs to be self-contained for proper display. This function:134 135- Ends each line with ``\x1b[0m`` if styles are active (prevents bleeding)136- Starts each subsequent line with the active style restored137 138:param lines: List of text lines, possibly containing SGR sequences.139:returns: List of lines with SGR codes propagated.140 141Example::142 143    >>> propagate_sgr(['\x1b[31mhello', 'world\x1b[0m'])144    ['\x1b[31mhello\x1b[0m', '\x1b[31mworld\x1b[0m']145 146This is useful in cases of making special editors and viewers, and is used for the147default modes (propagate_sgr=True) of :func:`wcwidth.wrap` and :func:`wcwidth.clip`.148 149When wrapping and clipping text containing SGR sequences, maybe a previous line enabled the BLUE150color--if we are viewing *only* the line following, we would want the carry over the BLUE color,151and all lines with sequences should end with terminating reset (``\x1b[0m``).152c3�L# �UHn[RU5v� M g7frr)�_SGR_QUICK_CHECK�search)rv�lines  rNrx� propagate_sgr.<locals>.<genexpr>>s���?����&�&�t�,�,��s�"$)�any�listr�r�r��finditerr�r�rc�153_SGR_RESETr~)�linesr�rbr��prefixr��output_lines       rN�
propagate_sgrr�$s���4�?��?�?�?�u��E�{���F��E���'��.��"�*�*�4�0�E�%�e�[�[�]�;�E�1�(.�f�m�4����&�&�%�154�2�K��
�
�k�"���MrM)rbrP�returnrR)rbrPr�rt)r�rtr�zlist[int | tuple[int, ...]])r�zIterator[int | tuple[int, ...]]r�r�r�r])rbrPr�rtr�rP)r�z
Sequence[str]r�z	list[str])r-�155__future__r�re�enumr�typingrrrrr156�compiler�r�r�rPr�rcr�r�r�r�r�r(rMrN�<module>r�s����#�157��6�6���&�7�&�Z�z�z�-�.���:�:�/�0���158�.�159�.�B�[��160M�'�8�<�+��36����:N�b/rM
codekingpro/portable-devtools · Team Ai