VBFj8DdZddlmZddlmZgdZddlmZddlm Z ddl m Z dd l m Z m Z mZmZmZmZmZdd lmZdd lmZdd lmZd dZ d!d"dZ d#d$dZdS)%z.This is a python implementation of wcswidth().) annotations)Optional)zwcwidth._constantszwcwidth._wcwidthzwcwidth.bisearchzwcwidth.table_graphemezwcwidth.table_vs16)table_grapheme_overrideswcwidth)bisearch)_EMOJI_ZWJ_SET_ISC_VIRAMA_SET_CATEGORY_MC_TABLE_FITZPATRICK_RANGE_REGIONAL_INDICATOR_SETresolve_terminalget_term_overrides)VS15_WIDE_TO_NARROW)VS16_NARROW_TO_WIDE)GRAPHEME_EXTENDtextstrstartintendreturnc0|dz}||kr[tt||tr3|dz }||kr(tt||t3||krt||dkrn|dz }||krt||tvrg|dz }||kr[tt||tr3|dz }||kr(tt||t3 |S)z Scan forward from *start* (base character) to end of a ZWJ grapheme cluster. Follows the UAX #29 GB11 pattern (ExtPict Extend* ZWJ x ExtPict) chained repeatedly until no more ZWJ joins are found. r )r ordrr )rrridxs ?C:\PYTHON\_runtimes\venv\Lib\site-packages\wcwidth/_wcswidth.py_scan_zwj_cluster_endrs !)C ))T#YAA) q ))T#YAA) )) tCy>>V # #  q 99T#Y>99 1HC))T#Y I I)q))T#Y I I)  JNautopwcsn Optional[int]unicode_versionambiguous_widthc|7|r#|rt|Sdkrtnfd}|t|nt |t|}d}d}d}d} d} d} d} t d} t d}t}||kr||}t|}|d kr#| r|dz }n|dz|kr d} d} |d z }nd} |dz }G|d kr|dkr|| | rd } d}|dz }i|d kr'|dkr!t| |r | d kr|dz}|dz }|d kr|tvrhd}|dz }|dkrHt||tvr,|dz }|dz}|dkrt||tv,|d zdkr |} |dz } n6td|cxkrtdkrnn| tvr|dz }C||}|dkrdS|dkr| rd } n | r|| z }|} n|} |}|} |} d} n,|tvrd} n |dkr||trd } d}d} nd} |dz }||k| r|| z }|S)a Given a unicode string, return its printable length on a terminal. See :ref:`Specification` for details of cell measurement. This implementation differs from Markus Khun's original POSIX C implementation, in that this ``wcswidth()`` processes graphemes strings yielded by :func:`wcwidth.iter_graphemes` defined by `Unicode Standard Annex #29`_. POSIX wcswidth(3) is not grapheme-aware and does not measure many kinds of Emojis or complex scripts correctly. :param pwcs: Measure width of given unicode string. :param n: When ``n`` is None (default), return the length of the entire string, otherwise only the first ``n`` characters are measured. :param unicode_version: Ignored. Retained for backwards compatibility. .. deprecated:: 0.3.0 Only the latest Unicode version is now shipped. :param ambiguous_width: Width to use for East Asian Ambiguous (A) characters. Default is ``1`` (narrow). Set to ``2`` for CJK contexts. :returns: The width, in cells, needed to display the first ``n`` characters of the unicode string ``pwcs``. Returns ``-1`` for C0 and C1 control characters! .. _`Unicode Standard Annex #29`: https://www.unicode.org/reports/tr29/ Nrc&t|dSNr!rcr&s rzwcswidth..cgaQ`>a>ar rF9.0.0rT)isascii isprintablelenrminrrr rrr r r r )r"r#r%r&_wcwidthr total_widthrlast_measured_idxlast_measured_ucslast_measured_wprev_was_virama cluster_width vs16_nw_table vs15_wn_table _bisearchcharucs ri_beforejws ` rwcswidthrH<soH yT\\^^y(8(8(:(:y4yy)Q..ww4a4a4a4aHy#d)))c!SYY&7&7CK COOM'0M'0MI ))Cy$ii &== qq3"#"'q"'q  &==.!33y*M:: " ! "  1HC  &==.!33)=99 !oQR>R>Rq 1HC  <<--- !G1ffT!W1H!H!HNIFA1ffT!W1H!H!Hq=A%%(+%1HC&%Q'3GGGG2DQ2GGGGGG'>99q HTNN q552 q55 " !  "}, ! ! #  # O#OO O # #"OO ! # # #7I(J(J #M " #OO#O q] ))`%}$ r T term_program bool | strc|7|r#|rt|St|}|rNt |}|j}|j}|j} |j} |j } |j } tj |} nd}d}d} d} d} d} i} dkrtnfd}|t|nt|t|}d}d}d}d}d}d}d}d}d}td }t d }t"}||kr||}t%|}|d kr{|r|dz }nr|dz|krb| rV|dkrP|t&vrGt)|||}|||}| |} | || |z z }d}d}d}d}d}|}d}d}|d z }nd}|dz }|d kr+|dkr%|r |||rn|||rd }d}|dz }|d kr@|dkr:|}!t#|!|}"| rt#|!| rd}"|"r |d kr|dz}|dz }|dkr|t*vrhd}#|dz }$|$dkrHt%||$t*vr,|#dz }#|$dz}$|$dkrt%||$t*v,|#d zdkr |}|dz }n6t,d|cxkrt,dkrnn|t&vr|dz }||}%|%dkrdS|%d kr|rt#||rd}%n|%d kr| rt#|| rd}%|%dkr| rt#|| rd }%n|%dkr| rt#|| rd}%|%dkr|rd }n{|rsd}&| ra|dkr[|||dz}'| |'} | || z}d}&d}n2|||}(| |(} | || z}n ||z }n||z }|&s|%}|}|}n|%}|}|}|}|}|%}d}n,|t.vrd}n |dkr||t0rd }d}d}nd}|dz }||k|r:| r3|dkr-|||}(| |(} | || z}n ||z }n||z }|S)a Given a unicode string, return its printable length on a terminal given by ``term_program``. See :ref:`Specification` for details of cell measurement. Unlike :func:`wcswidth`, this function applies per-terminal correction tables for emoji presentation and grapheme clusters. :param pwcs: Measure width of given unicode string. :param n: When ``n`` is None (default), return the length of the entire string, otherwise only the first ``n`` characters are measured. :param unicode_version: Ignored. Retained for backwards compatibility. :param ambiguous_width: Width to use for East Asian Ambiguous (A) characters. Default is ``1`` (narrow). Set to ``2`` for CJK contexts. :param term_program: Terminal software identifier for table correction. ``True`` (default) reads the ``TERM_PROGRAM`` or ``TERM`` environment variable for auto-detection. ``False`` disables override lookup. Accepts a canonical terminal name matching :func:`list_term_programs`, such as from XTVERSION_, ENQ_, or ``TERM_PROGRAM``. .. versionadded:: 0.8.0 :returns: The width, in cells, needed to display the first ``n`` characters of the unicode string ``pwcs``. Returns ``-1`` for C0 and C1 control characters! Nrc&t|dSr)rr*s rr,zwcstwidth..r-r rr.r/Fr0rr1r2r3r4T)r5r6r7rrnarrower vs16_narrower vs15_widerzeroer narrow_wider narrow_zeroerrgetrr8rrr rr rrr r r ))r"r#r%r&rIterm_canonical overrides _narrower_vs16_narrower _vs15_wider_zeroer _narrow_wider_narrow_zeroer_grapheme_overridesr9rr:rr;r<r=r> cluster_starttotal_before_clusterr?r@rArBrCrD cluster_endcluster override_wbase_ucs vs15_narrowrErFrGflushed candidate cluster_texts) ` r wcstwidthrhsmJ yT\\^^y(8(8(:(:y4yy&l33N!&~66 & "0* "!. "06:>JJ    *Q..ww4a4a4a4aHy#d)))c!SYY&7&7CK C OOMM'0M'0MI ))Cy$ii &== qq3'!-22-??"7>OQT"U"UK"#4[#@AG!4!8!8!A!AJ!-# _(DE ,.),.)*+*/(* ) #$"'q"'q  &==.!33 ")),=~"N"N ",m<< " ! "  1HC  &==.!33(H"8];;K $x+>> $#  !!33q 1HC  <<--- !G1ffT!W1H!H!HNIFA1ffT!W1H!H!Hq=A%%(+%1HC&%Q'3GGGG2DQ2GGGGGG'>99q HTNN q552 66i6HS)$<$<6AA !VVVHS'$:$:VA 66m6m(D(D6AA !VVV8C+H+HVA q55 3 !  3&1=A+=+=!%]37%: ;I!4!8!8!C!CJ!-&:Z&G "&() '+M#,='> %8%<%<\%J%J %1*>*KKK'=8KK=0K7$%M$'M+6( ! # '2$ #  # O#OO O # #"OO ! # # #7I(J(J #M " #OO#O q_ ))b )  )=A#5#5 c 12L,00>>J%2Z? }, = (K r )rrrrrrrr)Nr!r) r"rr#r$r%rr&rrr)Nr!rT) r"rr#r$r%rr&rrIrJrr)__doc__ __future__rtypingr__lazy_modules__rr9rr _constantsr r r r rrr table_vs15r table_vs16rtable_graphemerrrHrhrLr rrrs44""""""'&&&&&------------------,+++++++++++++++++@! HHHHHZ!# pppppppr