Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��j�� �%SrSSKJr SSKrSSKrSSKJr "SS\R5r\"SSS	SS39\"SSS	SS49\"SSS
SS59\"SSS
SS69\"SSSSS79\"SSSSS89S.r	S\9S'"SS\R5r"SS\R5rg)aV10`kitty text sizing protocol`_ (OSC 66) parsing and measurement.11 12The kitty text sizing protocol allows terminal apps to explicitly tell13terminals how many cells text occupies, using the escape sequence::14 15    ESC ] 66 ; metadata ; text BEL/ST16 17Metadata is colon-separated ``key=value`` pairs:18 19- ``s``: scale20- ``w``: width in cells21- ``n``: fractional numerator22- ``d``: fractional denominator23- ``v``: vertical alignment24- ``h``: horizontal alignment25 26Parsing is pretty straight-forward:27 28- When ``w > 0``, return ``s * w``.29- Otherwise ``w == 0``, ``s * wcswidth(inner_text_width)`` cells.30 31Numerator, denominator, and alignment codes and values are parsed but otherwise ignored32and have no effect on measurements made in this library.33 34.. _`kitty text sizing protocol`: https://sw.kovidgoyal.net/kitty/text-sizing-protocol/35 36.. versionadded:: 0.7.037�)�annotationsN�)�wcswidthc�>�\rSrSr%S\S'S\S'S\S'S\S'Srg	)38�39_FieldMeta�*�str�name�int�low�high�default�N)�__name__�40__module__�__qualname__�__firstlineno__�__annotations__�__static_attributes__r��YD:\code\apps\devtools\python\user_packages\Python313\site-packages\wcwidth/text_sizing.pyrr*s��41
�I�	�H�42
�I�
�Lrr�scale�)r43rr
r�width�	numerator��denominator�vertical_align��horizontal_align)�s�w�n�d�v�hzdict[str, _FieldMeta]�TEXT_FIELD_MAPPINGc��\rSrSr%SrSrS\S'SrS\S'SrS\S'Sr	S\S	'Sr44S\S45'SrS\S'SSjrSS
jr
\SSSjj5rSrg)�TextSizingParams�:a46Parsed parameters from a text sizing escape sequence (OSC 66).47 48:param scale: Scale factor (1-7). Text occupies ``scale`` rows tall and ``scale * width``49    columns wide.50:param width: Width in cells (0-7). When 0, width is auto-calculated from the inner text.51:param numerator: Fractional scaling numerator (0-15).52:param denominator: Fractional scaling denominator (0-15).53:param vertical_align: Vertical alignment (0=top, 1=bottom, 2=center).54:param horizontal_align: Horizontal alignment (0=left, 1=right, 2=center).55rrrrrrrrr c�^�SRU4Sj[R555nTRRSUS3$)z56Return a compact representation including only non-default fields.57 58This avoids verbose output when most fields are defaults.59z, c3�># �UHPn[TUR5UR:wdM)URS[TUR53v� MR g7f)�=N)�getattrr60r)�.0�field�selfs  �r�	<genexpr>�,TextSizingParams.__repr__.<locals>.<genexpr>UsN����L�*E�� '��e�j�j� 9�U�]�]� J�I��61�62�|�1�W�T�5�:�:�-F�,G�H�*E�s63�(A�,A�(�))�joinr'�values�	__class__r)r1�repr_fmts` r�__repr__�TextSizingParams.__repr__NsL����9�9�L�*<�*C�*C�*E�L�L���.�.�)�)�*�!�H�:�Q�7�7rc���/n[R5HAup#[XR5=oCR:wdM+URUSU35 MC SR
U5$)z0Build and return sub-part of an OSC 66 sequence.r-�:)r'�itemsr.r64r�appendr6)r1�parts�	field_keyr0�vals     r�
make_sequence�TextSizingParams.make_sequenceZs\���� 2� 8� 8� :��I��t�Z�Z�0�0��]�]�B����	�{�!�C�5�1�2�!;��x�x���rc���0nU(dU"5$URS5GH
nSU;aUS:Xa[SU<SU<35eM%URS5upVn[R	U5nUcUS:Xa[SUSU<35eMk[U5n	US:XaZX�R:�dX�R:a<[SUSU<SUS
URSURSUR35e[UR[URU	55X8R'GM U"S0UD6$![a(n65US:Xa[S	USU<S66U6735U68eSn69A70GMGSn71A72ff=f)a073Parse colon-separated ``key=value`` metadata string.74 75:param raw: Metadata string, e.g. ``'s=2:w=3'``.76:param control_codes: 'parse' or 'strict'.77:raises ValueError: If ``control_codes='strict'`` unrecognized text sizing parameters raise78    ValueError.79:returns: Parsed parameters with values clamped to valid ranges.80    Unknown keys are ignored. Non-integer values use defaults.81 82Example::83 84    >>> TextSizingParams.from_params('s=2:w=3')85    TextSizingParams(scale=2, width=3, numerator=0, denominator=0,             vertical_align=0, horizontal_align=0)86r=r-�strictz5Expected '=' in text sizing parameter (key=val), got z in OSC 66 sequence, NzUnknown text sizing field 'z' in OSC 66 sequence, zIllegal text sizing value 'z: z!Out of bounds text sizing value 'z: allowed range for 'z' (z) is z to r)�split�87ValueError�	partitionr'�getrr
rr88�max�min)�cls�raw�
control_codes�kwargs�part�key�_eqrBr0�value�excs           r�from_params�TextSizingParams.from_paramscs���$)+����5�L��I�I�c�N�D��$�� �H�,�$�(,�,0�8�3H���&Q�R�R�� �N�N�3�/�M�C�c�&�*�*�3�/�E��}� �H�,�$�'B�3�%�H<�<?�7�&D�E�E��
��C�����(�e�j�j�.@�E�I�I�DU� �#D�S�E�J8�8;�w�?7�7:�e�3�u�z�z�l�K'�',�y�y�k��e�j�j�\�"C�D�D�"%�U�Y�Y��E�J�J��0F�!G�F�:�:��7#�8�}�V�}����
� �H�,�$�'B�3�%�H<�<?�7�"�S�E�&K�L�QT�U���
�s�D<�<89E.�E)�)E.rN��returnr	��parse)rNr	rOr	rYr))rrrr�__doc__rrrrrrr r:rC�classmethodrVrrrrr)r):sb��90��E�3�N��E�3�N��I�s���K����N�C����c��918���0��0rr)c�h�\rSrSr%SrS\S'S\S'S\S'\S
SSjj5rSSS	jjrSS92jr	Sr93g)�94TextSizing�zBBasic horizontal width measurement for kitty text sizing protocol.r)�paramsr	�text�95terminatorc��U"[RURS5US9URS5URS5S9$)a�96Parse using matching OSC 66 Sequence.97 98:param match: match object from :attr:`wcwidth.escape_sequences.TEXT_SIZING_PATTERN`.99:param control_codes: 'parse' or 'strict', same meaning as delegated by100    :func:`wcwidth.width`.101:raises ValueError: When ``control_codes='strict'`` for unrecognized, invalid, or out of102    bounds text sizing parameters.103:returns: TextSizing object from parsed sequence104 105Example::106 107    from wcwidth.escape_sequences import TEXT_SIZING_PATTERN108    >>> TextSizing.from_match(TEXT_SIZING_PATTERN.match('\x1b]66;w=2;XY\x07'))109    TextSizing(params=TextSizingParams(scale=1, width=2, numerator=0, denominator=0, \110    vertical_align=0, horizontal_align=0), text='XY', terminator='\x07')111r)rOr�)rarbrc)r)rV�group)rM�matchrOs   r�112from_match�TextSizing.from_match�sC��&�*�6�6�u�{�{�1�~�Ub�6�c����A��#�k�k�!�n�.�	.rc���URRS:�a-URRURR-$[URUS9nURR[SU5-$)a�113Calculate the display width of a text sizing sequence.114 115:param ambiguous_width: Width for East Asian Ambiguous characters.116:returns: Display width in terminal cells. When ``width > 0``, returns117    ``params.scale * params.width``. When ``width == 0``, returns118    ``params.scale * measured_inner_width``.119 120.. note: Fractional scaling (numerator/denominator) does not affect the121    cell count, it adjusts only the font size within the cells allocated by 'w'.122r)�ambiguous_width)rarrrrbrK)r1rkr"s   r�
display_width�TextSizing.display_width�s`���;�;���q� ��;�;�$�$�t�{�{�'8�'8�8�8��T�Y�Y��@���{�{� � �3�q�!�9�,�,rc�n�SURR5SURUR3$)z3Build and return complete OSC 66 Terminal Sequence.z]66;�;)rarCrbrc)r1s rrC�TextSizing.make_sequence�s0���$�+�+�3�3�5�6�a��	�	�{�4�?�?�BS�T�TrrNrZ)rgz
re.Match[str]rOr	rYr_)r)rkrrYrrX)rrrrr\rr]rhrlrCrrrrr_r_�s2��L���123
�I��O��.��.�,-�"Urr_)
r\�124__future__r�re�typing�	_wcswidthr�125NamedTuplerr'rr)r_rrr�<module>rvs����<#�126�
� ���"�"��127��a�a��	;�	��a�a��	;�	��!�"�a�	@�	��A�B��	B�	�)�q�q�!�	D�	�+���A�	F�
-H��)�H�Z�v�(�(�Z�z1U��"�"�1Ur
codekingpro/portable-devtools · Team Ai