Files
tamigo-cli/venv/lib/python3.12/site-packages/wcwidth/__pycache__/textwrap.cpython-312.pyc

214 lines
24 KiB
Plaintext
Raw Normal View History

<EFBFBD>
<00><16>iEq<00><01>l<00>dZddlmZddlZddlZddlZddlmZmZddl m
Z ddl m Z ddl mZdd lmZdd
lmZerdd lmZmZGd <0C>d e<08>Zej.d<0E>Zdd<0F>Zdd<10>Zdd<11>ZGd<12>dej8<00>Zdddddddddddddddd<1A> d d<1B>Zy)!z<>
Sequence-aware text wrapping functions.
This module provides functions for wrapping text that may contain terminal escape sequences, with
proper handling of Unicode grapheme clusters and character display widths.
<EFBFBD>)<01> annotationsN)<02> TYPE_CHECKING<4E>
NamedTuple<EFBFBD>)<01>width)<01>iter_sequences)<01>iter_graphemes)<01> propagate_sgr)<01>ZERO_WIDTH_PATTERN)<02>Any<6E>Literalc<01>0<00>eZdZUdZded<ded<ded<y)<07>_HyperlinkStatez>State for tracking an open OSC 8 hyperlink across line breaks.<2E>str<74>url<72>params<6D>
terminatorN)<05>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>__annotations__<5F><00><00>V/home/daniel/Projects/tamigo-cli/venv/lib/python3.12/site-packages/wcwidth/textwrap.pyrrs<00><00>H<> <0C>H<EFBFBD> <0F>K<EFBFBD><13>Orrz*\x1b]8;([^;]*);([^\x07\x1b]*)(\x07|\x1b\\)c<01><><00>tj|<00>x}r;t|jd<01>|jd<02>|jd<03><00><04>Sy)z0Parse OSC 8 open sequence, return state or None.<2E>r<00><00>rrrN)<04>_HYPERLINK_OPEN_RE<52>matchr<00>group)<02>seq<65>ms r<00>_parse_hyperlink_openr%'sC<00><00> <1F> %<25> %<25>c<EFBFBD> *<2A>*<2A><01>*<2A><1E>1<EFBFBD>7<EFBFBD>7<EFBFBD>1<EFBFBD>:<3A>a<EFBFBD>g<EFBFBD>g<EFBFBD>a<EFBFBD>j<EFBFBD>Q<EFBFBD>W<EFBFBD>W<EFBFBD>UV<55>Z<EFBFBD>X<>X<> rc<01><00>d|<01>d|<00>|<02><00>S)zGenerate OSC 8 open sequence.z]8;<3B>;rrs r<00>_make_hyperlink_openr(.s<00><00> <14>V<EFBFBD>H<EFBFBD>A<EFBFBD>c<EFBFBD>U<EFBFBD>:<3A>,<2C> /<2F>/rc<01> <00>d|<00><00>S)zGenerate OSC 8 close sequence.z]8;;r)rs r<00>_make_hyperlink_closer*3s<00><00> <15>j<EFBFBD>\<5C> "<22>"rc<01><><00><00>eZdZdZddddd<05> d<14>fd<06>Zedd<07><04>Zdd<08>Zdd <09>Zdd
<EFBFBD>Z dd <0B>Z
dd <0C>Z dd <0A>Z dd<0E>Z dd<0F>Zdd<10>Zdd<11>Zdd<12>Z<11>xZS)<1E>SequenceTextWrappera<72>
Sequence-aware text wrapper extending :class:`textwrap.TextWrapper`.
This wrapper properly handles terminal escape sequences and Unicode grapheme clusters when
calculating text width for wrapping.
This implementation is based on the SequenceTextWrapper from the 'blessed' library, with
contributions from Avram Lubkin and grayjk.
The key difference from the blessed implementation is the addition of grapheme cluster support
via :func:`~.iter_graphemes`, providing width calculation for ZWJ emoji sequences, VS-16 emojis
and variations, regional indicator flags, and combining characters.
OSC 8 hyperlinks are handled specially: when a hyperlink must span multiple lines, each line
receives complete open/close sequences with a shared ``id`` parameter, ensuring terminals
treat the fragments as a single hyperlink for hover underlining. If the original hyperlink
already has an ``id`` parameter, it is preserved; otherwise, one is generated.
<20>parse<73>r<00><03> control_codes<65>tabsize<7A>ambiguous_widthc <01>R<00><01>t<00>|<00>dd|i|<05><01>||_||_||_y)a<>
Initialize the wrapper.
:param width: Maximum line width in display cells.
:param control_codes: How to handle control sequences (see :func:`~.width`).
:param tabsize: Tab stop width for tab expansion.
:param ambiguous_width: Width to use for East Asian Ambiguous (A) characters.
:param kwargs: Additional arguments passed to :class:`textwrap.TextWrapper`.
rNr)<05>super<65>__init__r0r1r2)<07>selfrr0r1r2<00>kwargs<67> __class__s <20>rr5zSequenceTextWrapper.__init__Ls1<00><><00> <0E><07><18>/<2F>u<EFBFBD>/<2F><06>/<2F>*<2A><04><1A><1E><04> <0C>.<2E><04>rc<01>,<00>tjd<01>S)z7Generate unique hyperlink id as 8-character hex string.<2E>)<02>secrets<74> token_hexrrr<00>_next_hyperlink_idz&SequenceTextWrapper._next_hyperlink_id_s<00><00><17> <20> <20><11>#<23>#rc<01>\<00>t||j|j|j<00><01>S)z,Measure text width accounting for sequences.r/)<04>_widthr0r1r2<00>r6<00>texts rr?zSequenceTextWrapper._widthds(<00><00><15>d<EFBFBD>$<24>*<<3C>*<<3C>d<EFBFBD>l<EFBFBD>l<EFBFBD>&*<2A>&:<3A>&:<3A><<3C> <rc<01>v<00>g}t|<01>D]\}}|r<01> |j|<03><00>dj|<02>S)z'Strip all terminal sequences from text.<2E><00>r<00>append<6E>join<69>r6rA<00>result<6C>segment<6E>is_seqs r<00>_strip_sequencesz$SequenceTextWrapper._strip_sequencesis><00><00><13><06>-<2D>d<EFBFBD>3<> '<27>O<EFBFBD>G<EFBFBD>V<EFBFBD><19><16> <0A> <0A>g<EFBFBD>&<26> '<27><12>w<EFBFBD>w<EFBFBD>v<EFBFBD><EFBFBD>rc<01>v<00>g}t|<01>D]\}}|s<01> |j|<03><00>dj|<02>S)z*Extract only terminal sequences from text.rCrDrGs r<00>_extract_sequencesz&SequenceTextWrapper._extract_sequencesqs><00><00><13><06>-<2D>d<EFBFBD>3<> '<27>O<EFBFBD>G<EFBFBD>V<EFBFBD><15><16> <0A> <0A>g<EFBFBD>&<26> '<27><12>w<EFBFBD>w<EFBFBD>v<EFBFBD><EFBFBD>rc<01><><00>g}d}d}d}t|<01>D]<5D>\}}|sR|r+|r)|dj<00>s|dz }|j|<04>|D]}|dz }|j|<04>||z }<03>d}<05>Z|jd<06>} |jd<07>r-|r+|dj<00>s| s|dz }|j|<04>|t |<06>z }| }<05><>|j|<04>t
j j||<03>}
|
s|r|gSg} d} t |
<EFBFBD>} t|
<EFBFBD>D]V\}}t |<0F>}| dk(rdn|| dz
}|| dz
k(r|d}n || |zdz
}||k7r| j|||<00>| |z } <0C>X| S) a<>
Sequence-aware variant of :meth:`textwrap.TextWrapper._split`.
This method ensures that terminal escape sequences don't interfere with the text splitting
logic, particularly for hyphen-based word breaking. It builds a position mapping from
stripped text to original text, calls the parent's _split on stripped text, then maps chunks
back.
OSC hyperlink sequences are treated as word boundaries::
>>> wrap('foo \x1b]8;;https://example.com\x07link\x1b]8;;\x07 bar', 6)
['foo', '\x1b]8;;https://example.com\x07link\x1b]8;;\x07', 'bar']
Both BEL (``\x07``) and ST (``\x1b\\``) terminators are supported.
rCrF<> r<00>z]8;;\z]8;;z]<5D><><EFBFBD><EFBFBD><EFBFBD>) r<00>isspacerE<00>
startswith<EFBFBD>len<65>textwrap<61> TextWrapper<65>_split<69> enumerate)r6rA<00>char_end<6E> stripped_text<78> original_pos<6F>prev_was_hyperlink_closerIrJ<00>char<61>is_hyperlink_close<73>stripped_chunksrH<00> stripped_pos<6F>
num_chunks<EFBFBD>idx<64>chunk<6E> chunk_len<65>
start_orig<EFBFBD>end_origs rrWzSequenceTextWrapper._splitys<><00><00>0!<21><08><1A> <0A><18> <0C>#(<28> <20>-<2D>d<EFBFBD>3<> ><3E>O<EFBFBD>G<EFBFBD>V<EFBFBD><19>+<2B><07><07><01>
<EFBFBD>@R<>@R<>@T<>!<21>S<EFBFBD>(<28>M<EFBFBD><1C>O<EFBFBD>O<EFBFBD>L<EFBFBD>1<>#<23>*<2A>D<EFBFBD> <20>A<EFBFBD>%<25>L<EFBFBD><1C>O<EFBFBD>O<EFBFBD>L<EFBFBD>1<>!<21>T<EFBFBD>)<29>M<EFBFBD>*<2A>,1<>(<28>%,<2C>%7<>%7<>8Z<38>%[<5B>"<22>
<1C>&<26>&<26>w<EFBFBD>/<2F>M<EFBFBD>%<25>b<EFBFBD>)<29>1<>1<>3<>-<2D>%<25><13>,<2C> <0A> <20><0F><0F> <0C>5<><1D><03>G<EFBFBD> <0C>,<2C> <0C>+=<3D>(<28>3 ><3E>8 <11><0F><0F> <0C>%<25>#<23>.<2E>.<2E>5<>5<>d<EFBFBD>M<EFBFBD>J<><0F><1F>4<EFBFBD><18>6<EFBFBD>M<EFBFBD><1F><06><18> <0C><18><1F>)<29>
<EFBFBD>#<23>O<EFBFBD>4<> &<26>J<EFBFBD>C<EFBFBD><15><1B>E<EFBFBD>
<EFBFBD>I<EFBFBD>+<2B>a<EFBFBD>/<2F><11>X<EFBFBD>l<EFBFBD>Q<EFBFBD>>N<>5O<35>J<EFBFBD><13>j<EFBFBD>1<EFBFBD>n<EFBFBD>$<24>#<23>B<EFBFBD><<3C><08>#<23>L<EFBFBD>9<EFBFBD>$<<3C>q<EFBFBD>$@<40>A<><08><1A>X<EFBFBD>%<25><16> <0A> <0A>d<EFBFBD>:<3A>h<EFBFBD>7<>8<> <18>I<EFBFBD> %<25>L<EFBFBD># &<26>&<16> rc<01>t <00>|sgS|j<00>{|jdkDr |j}n |j}|j|<02>|j|jj <00><00>z|j kDr td<03><00>g}d}d}d}tt|<01><00>}|<01>r g}d}|r |jn |j}|j |j|<02>z
} |<05>6t|j|j|j<00>}
|
|dz|d<|j|d<00>} |jr:|r8| r6| j!<00>s&|j#|d<00>} |d=| r |r | |dz|d<|rG|d} |j| <0A>}||z| kr%|j%|j'<00><00>||z }nn|r<01>G|r]|j|d<00>| kDrF|j)|||| <09>|jdj+|<07><00>}|r|ds |d=|r|ds<01> |r|j|d<00>nd}|jrQ|rO|rM|j!<00>s=|j#|d<00>} ||j|d<00>z}|d=| r |r |d| z|d<|<07>r| xsA|jxr3t-|<01>dk(xr#|j|d<00>j!<00> }|j<00>$t-|<03>dz|jks |<10>rh|| k<00>rbdj+|<07>}|j/||<05>}|<12><01>|<06>[d|jvr |j}n@|jr!d|j1<00><00>d |j<00><00>}nd|j1<00><00><00>}|t3|j<00>z }d|jvr_t|j|j|j<00>}t|j||j<00>}|j5||d<02>}t7|j||j<00>}nd}d}|jr|j9<00>}|j%||z<00>d
}<04>nC|j|j<00>}|r<>|j|d<00>}|j!<00>rj||z| krbdj+|<07>}|j/||<05>}|<12>|t3|j<00>z }|j%||z|jz<00> |S||j|d<00>z}|d=|r<01><>|rJ|j;|d<00>}|j|<17>|z|j kr||jz|d< |S|j%||jj <00>z<00> |S|r<02><05> |S) a<>
Wrap chunks into lines using sequence-aware width.
Override TextWrapper._wrap_chunks to use _width instead of len. Follows stdlib's algorithm:
greedily fill lines, handle long words. Also handle OSC hyperlink processing. When
hyperlinks span multiple lines, each line gets complete open/close sequences with matching
id parameters for hover underlining continuity per OSC 8 spec.
Nrz#placeholder too large for max widthTrrQrCzid=<3D>:F)<1E> max_lines<65>subsequent_indent<6E>initial_indentr?<00> placeholder<65>lstripr<00>
ValueError<EFBFBD>list<73>reversedr(rrrrK<00>drop_whitespace<63>striprMrE<00>pop<6F>_handle_long_wordrFrT<00>_track_hyperlink_stater=r*<00>replacer<00>rstrip<69>_rstrip_visible)r6<00>chunks<6B>indent<6E>lines<65> is_first_line<6E>hyperlink_state<74>current_hyperlink_id<69> current_line<6E> current_width<74>
line_width<EFBFBD>open_seq<65>stripped<65> sequencesrc<00> chunk_width<74> stripped_last<73>no_more_content<6E> line_content<6E> new_state<74>old_open<65>new_open<65> placeholder_w<5F> last_text<78> prev_lines r<00> _wrap_chunksz SequenceTextWrapper._wrap_chunks<6B>s<00><00><16><15>I<EFBFBD> <0F>><3E>><3E> %<25><13>~<7E>~<7E><01>!<21><1D>/<2F>/<2F><06><1D>,<2C>,<2C><06><14> <0B> <0B>F<EFBFBD>#<23><1A>k<EFBFBD>k<EFBFBD>$<24>"2<>"2<>"9<>"9<>";<3B><<3C>=<3D><1A>j<EFBFBD>j<EFBFBD>!<21>!<21>!F<>G<>G<><1D><05><1C> <0A>26<32><0F>+/<2F><1C><16>h<EFBFBD>v<EFBFBD>&<26>'<27><06><14>&(<28>L<EFBFBD><1D>M<EFBFBD>-:<3A>T<EFBFBD>(<28>(<28>t<EFBFBD>?U<>?U<>F<EFBFBD><1D><1A><1A>d<EFBFBD>k<EFBFBD>k<EFBFBD>&<26>&9<>9<>J<EFBFBD><1F>*<2A>/<2F>#<23>'<27>'<27><1F>)?<3F>)?<3F><1F>A[<5B>A[<5B>]<01><08>%<25><06>r<EFBFBD>
<EFBFBD>2<><06>r<EFBFBD>
<EFBFBD>
<1C>,<2C>,<2C>V<EFBFBD>B<EFBFBD>Z<EFBFBD>8<>H<EFBFBD><13>#<23>#<23><05>(<28>8<EFBFBD>><3E>><3E>CS<43> <20>3<>3<>F<EFBFBD>2<EFBFBD>J<EFBFBD>?<3F> <09><1A>2<EFBFBD>J<EFBFBD><1C><16>!*<2A>V<EFBFBD>B<EFBFBD>Z<EFBFBD>!7<>F<EFBFBD>2<EFBFBD>J<EFBFBD><19><1E>r<EFBFBD>
<EFBFBD><05>"<22>k<EFBFBD>k<EFBFBD>%<25>0<> <0B> <20>;<3B>.<2E>*<2A><<3C> <20>'<27>'<27><06>
<EFBFBD>
<EFBFBD> <0C>5<>!<21>[<5B>0<>M<EFBFBD><19><19><16>$<24>+<2B>+<2B>f<EFBFBD>R<EFBFBD>j<EFBFBD>1<>J<EFBFBD>><3E><14>&<26>&<26><1A>L<EFBFBD>-<2D><1A><12>!%<25> <0B> <0B>B<EFBFBD>G<EFBFBD>G<EFBFBD>L<EFBFBD>,A<> B<> <0A><1C>V<EFBFBD>B<EFBFBD>Z<EFBFBD><1E>r<EFBFBD>
<EFBFBD><1D>V<EFBFBD>B<EFBFBD>Z<EFBFBD> HT<01>D<EFBFBD>1<>1<>,<2C>r<EFBFBD>2B<32>C<>Y[<5B>M<EFBFBD><14>$<24>$<24><1C>!<21>-<2D>*=<3D>*=<3D>*?<3F> <20>3<>3<>L<EFBFBD><12>4D<34>E<> <09><1D><14><1B><1B>\<5C>"<22>-=<3D>!><3E>><3E> <0A> <20><12>$<24><1C><1C>'3<>B<EFBFBD>'7<>)<29>'C<>L<EFBFBD><12>$<24><1B> <1F>J<EFBFBD>A<01><18>(<28>(<28>A<01><17><06>K<EFBFBD>1<EFBFBD>$<24>A<01><1C>-<2D>-<2D>f<EFBFBD>Q<EFBFBD>i<EFBFBD>8<>><3E>><3E>@<40>@<40>  <20> <19>N<EFBFBD>N<EFBFBD>*<2A><1B>E<EFBFBD>
<EFBFBD>Q<EFBFBD><0E><14><1E><1E>7<>'<27>)<29>Z<EFBFBD>7<>#%<25>7<EFBFBD>7<EFBFBD><<3C>#8<>L<EFBFBD>!%<25> ;<3B> ;<3B>L<EFBFBD>/<2F> Z<>I<EFBFBD>!<21>,<2C>/<2F>7<>$<24> <09>(8<>(8<>8<>7@<40>7G<37>7G<37> 4<>!*<2A>!1<>!1<>'*<2A>$<24>*A<>*A<>*C<>)D<>A<EFBFBD>i<EFBFBD>FV<46>FV<46>EW<45>$X<>!5<>:=<3D>T<EFBFBD>=T<>=T<>=V<><W<>7X<37> 4<>$<24>(=<3D>i<EFBFBD>>R<>>R<>(S<>S<> <0C>!<21> <09>(8<>(8<>8<>';<3B> )<29> <0A> <0A>y<EFBFBD>/?<3F>/?<3F><19>AU<41>AU<41>(W<01>H<EFBFBD>';<3B> )<29> <0A> <0A>/C<>Y<EFBFBD>EY<45>EY<45>([<01>H<EFBFBD>+7<>+?<3F>+?<3F><08>(<28>TU<54>+V<>L<EFBFBD>+:<3A>%<25>M<EFBFBD>M<EFBFBD>+?<3F><19>AU<41>AU<41>+W<01><0F>+/<2F><0F>/3<>,<2C><1C>+<2B>+<2B>'3<>':<3A>':<3A>'<<3C> <0C><19>L<EFBFBD>L<EFBFBD><16>,<2C>!6<>7<>$)<29>M<EFBFBD>%)<29>K<EFBFBD>K<EFBFBD><04>0@<40>0@<40>$A<>M<EFBFBD>&<26>$(<28>$9<>$9<>,<2C>r<EFBFBD>:J<>$K<> <09>%<25>O<EFBFBD>O<EFBFBD>-<2D>$1<>M<EFBFBD>$A<>Z<EFBFBD>$O<>+-<2D>7<EFBFBD>7<EFBFBD><<3C>+@<40>L<EFBFBD>(,<2C>(C<>(C<> ,<2C>o<EFBFBD>)?<3F>I<EFBFBD>(<28>4<> ,<2C>0E<30>$-<2D>$8<>$8<>1:<3A>!:<3A> <0C>!<21>L<EFBFBD>L<EFBFBD><16>,<2C>)><3E><14>AQ<41>AQ<41>)Q<>R<>!<21><1A><14> <0C>&<26><14><1B><1B>\<5C>"<22>5E<35>)F<>F<> <0A>(<28><12>,<2C>'<27>!<21>(,<2C>(<<3C>(<<3C>U<EFBFBD>2<EFBFBD>Y<EFBFBD>(G<>I<EFBFBD> $<24> <0B> <0B>I<EFBFBD> 6<><1D> F<>'+<2B>z<EFBFBD>z<EFBFBD>!2<>,5<><04>8H<38>8H<38>,H<><05>b<EFBFBD> <09> %<25><15> <0C><1E> <0C> <0C>V<EFBFBD>d<EFBFBD>.><3E>.><3E>.E<>.E<>.G<>%G<>H<><19><14> <0C>_<15>^<15> rc<01><><00>t|<01>D]8\}}|s<01> t|<03>}|<05>|jr|}<02>%|jd<02>s<01>7d}<02>:|S)z<>
Track hyperlink state through text.
:param text: Text to scan for hyperlink sequences.
:param state: Current state or None if outside hyperlink.
:returns: Updated state after processing text.
NrP)rr%rrS)r6rA<00>staterIrJ<00> parsed_links rruz*SequenceTextWrapper._track_hyperlink_state<74>sU<00><00> .<2E>d<EFBFBD>3<> !<21>O<EFBFBD>G<EFBFBD>V<EFBFBD><15>3<>G<EFBFBD><<3C> <0B><1E>*<2A>{<7B><EFBFBD><EFBFBD>'<27>E<EFBFBD><1C>'<27>'<27>(J<>K<> <20>E<EFBFBD>  !<21><15> rc<01><00>|dkrd}n||z
}|d}|jr<>d}d}|jrc|j|<06>} t| <09>|kDrD| j dd|<05>}
|
dkDr,t d<06>| d|
D<00><00>r|j ||
dz<00>}d}|r|} n*|j||<05>} | dk(r|s|j|<06>} |j|d| <00>|| d|d<y|s |j|j<00><00>yy) z<>
Sequence-aware :meth:`textwrap.TextWrapper._handle_long_word`.
This method ensures that word boundaries are not broken mid-sequence, and respects grapheme
cluster boundaries when breaking long words.
rrQFr<00>-c3<01>&K<00>|] }|dk7<00><01><00> y<01>w)r<>Nr)<02>.0<EFBFBD>cs r<00> <genexpr>z8SequenceTextWrapper._handle_long_word.<locals>.<genexpr><3E>s<00><00><><00>-V<>1<EFBFBD>a<EFBFBD>3<EFBFBD>h<EFBFBD>-V<>s<00>NT) <0B>break_long_words<64>break_on_hyphensrKrT<00>rfind<6E>any<6E>_map_stripped_pos_to_original<61>_find_break_position<6F>_find_first_grapheme_endrErs) r6<00>reversed_chunks<6B>cur_line<6E>cur_lenr<00>
space_leftrc<00>break_at_hyphen<65>
hyphen_endr<EFBFBD><00>
hyphen_pos<EFBFBD>
actual_ends rrtz%SequenceTextWrapper._handle_long_word<72>s<00><00> <11>1<EFBFBD>9<EFBFBD><1A>J<EFBFBD><1E><17><1F>J<EFBFBD><1F><02>#<23><05> <0F> <20> <20>#<23>O<EFBFBD><1A>J<EFBFBD><14>$<24>$<24><1F>0<>0<><15>7<><08><16>x<EFBFBD>=<3D>:<3A>-<2D>!)<29><1E><1E><03>Q<EFBFBD>
<EFBFBD>!C<>J<EFBFBD>!<21>A<EFBFBD>~<7E>#<23>-V<><08><1B>*<2A>@U<>-V<>*V<>%)<29>%G<>%G<><05>z<EFBFBD>\]<5D>~<7E>%^<5E>
<EFBFBD>*.<2E><0F><1F>'<27>
<EFBFBD>!<21>6<>6<>u<EFBFBD>j<EFBFBD>I<>
<EFBFBD>
<1E><11>?<3F>8<EFBFBD>!%<25>!><3E>!><3E>u<EFBFBD>!E<>J<EFBFBD> <14>O<EFBFBD>O<EFBFBD>E<EFBFBD>+<2B>:<3A>.<2E> /<2F>"'<27>
<EFBFBD> <0B>"4<>O<EFBFBD>B<EFBFBD> <1F><19> <14>O<EFBFBD>O<EFBFBD>O<EFBFBD>/<2F>/<2F>1<> 2<>rc<01><><00>d}d}t|<01>D]M\}}|r|t|<05>z }<04>|t|<05>z|kDr
|||z
zcS|t|<05>z }|t|<05>z }<04>O|S)z?Map a position in stripped text back to original text position.r)rrT)r6rAr`<00> stripped_idx<64> original_idxrIrJs rr<>z1SequenceTextWrapper._map_stripped_pos_to_original<61>sz<00><00><18> <0C><18> <0C>-<2D>d<EFBFBD>3<> -<2D>O<EFBFBD>G<EFBFBD>V<EFBFBD><15><1C><03>G<EFBFBD> <0C>,<2C> <0C><1D><03>G<EFBFBD> <0C>,<2C>|<7C>;<3B>#<23>|<7C>l<EFBFBD>'B<>C<>C<><1C><03>G<EFBFBD> <0C>,<2C> <0C><1C><03>G<EFBFBD> <0C>,<2C> <0C> -<2D><1C>rc<01>6<00>d}d}|t|<01>kr<>||}|dk(r)tj||<03>}|r|j<00>}<03>At t ||<03><03><00>}|j |<07>}||z|kDr|S||z }|t|<07>z }|t|<01>kr<01><>|S)z;Find string index in text that fits within max_width cells.r<00>)<01>start)rTr r!<00>end<6E>nextr r?) r6rA<00> max_widthrb<00> width_so_farr]r!<00>grapheme<6D>grapheme_widths rr<>z(SequenceTextWrapper._find_break_position<6F>s<><00><00><0F><03><18> <0C><11>C<EFBFBD><04>I<EFBFBD>o<EFBFBD><17><03>9<EFBFBD>D<EFBFBD><14>v<EFBFBD>~<7E>*<2A>0<>0<><14>s<EFBFBD>;<3B><05><18><1F>)<29>)<29>+<2B>C<EFBFBD><1C><1C>N<EFBFBD>4<EFBFBD>s<EFBFBD>;<3B><<3C>H<EFBFBD>!<21>[<5B>[<5B><18>2<>N<EFBFBD><1B>n<EFBFBD>,<2C>y<EFBFBD>8<><1A>
<EFBFBD> <18>N<EFBFBD> *<2A>L<EFBFBD> <0F>3<EFBFBD>x<EFBFBD>=<3D> <20>C<EFBFBD>%<12>C<EFBFBD><04>I<EFBFBD>o<EFBFBD>,<13>
rc<01><<00>ttt|<01><00><00>S)z,Find the end position of the first grapheme.)rTr<>r r@s rr<>z,SequenceTextWrapper._find_first_grapheme_ends<00><00><12>4<EFBFBD><0E>t<EFBFBD>,<2C>-<2D>.<2E>.rc<01><><00>tt|<01><00>}d}t|<02>D]\}\}}|r<01> |j<00>s<01>|}<03> |dk(ryg}t|<02>D]X\}\}}||kr|j |<05><00> ||k(r |j |j<00><00><00>E|s<01>H|j |<05><00>Zdj |<07>S)zAStrip trailing visible whitespace, preserving trailing sequences.rQrC)rorrXrwrErF)r6rA<00>segments<74>last_vis<69>irIrJrHs rrxz#SequenceTextWrapper._rstrip_visibles<><00><00><17><0E>t<EFBFBD>,<2C>-<2D><08><15><08>$-<2D>h<EFBFBD>$7<> <1D> <20>A<EFBFBD> <20><07><16><19>g<EFBFBD>n<EFBFBD>n<EFBFBD>.<2E><1C><08> <1D> <14>r<EFBFBD>><3E><15><13><06>$-<2D>h<EFBFBD>$7<> '<27> <20>A<EFBFBD> <20><07><16><10>8<EFBFBD>|<7C><16> <0A> <0A>g<EFBFBD>&<26><12>h<EFBFBD><1D><16> <0A> <0A>g<EFBFBD>n<EFBFBD>n<EFBFBD>.<2E>/<2F><17><16> <0A> <0A>g<EFBFBD>&<26>  '<27><12>w<EFBFBD>w<EFBFBD>v<EFBFBD><EFBFBD>r<00><01>F) r<00>intr0<00>$Literal['parse', 'strict', 'ignore']r1r<>r2r<>r7r <00>return<72>None)r<>r)rArr<>r<>)rArr<>r)rArr<><00> list[str])ryr<>r<>r<>)rArr<><00>_HyperlinkState | Noner<65>r<>)
r<EFBFBD>r<>r<>r<>r<>r<>rr<>r<>r<>)rArr`r<>r<>r<>)rArr<>r<>r<>r<>)rrrrr5<00> staticmethodr=r?rKrMrWr<>rurtr<>r<>r<>rx<00> __classcell__)r8s@rr,r,8s<><00><><00><08>&/<2F>GN<47> !<21>()<29>/<2F> D<>/<2F><1D>/<2F>#&<26>/<2F><1F> /<2F>$(<28> /<2F>&<12>$<24><12>$<24><<3C>
<1F><1F>\<16>|s<15>j<15><1B><15>)<29><15>.D<><15>&/3<>$-<2D>/3<>8;<3B>/3<>!$<24>/3<>)-<2D>/3<>b<1C>&<13>:/<2F>rr,r-r.TrCFz [...])r0r1<00> expand_tabs<62>replace_whitespacer2rkrj<00>fix_sentence_endingsr<73>r<>rqrirlr
c<01>t<00>t||||||||| |
| | | |<0E><01>}|j|<00>}|r t|<11>}|S)u
Wrap text to fit within given width, returning a list of wrapped lines.
Like :func:`textwrap.wrap`, but measures width in display cells rather than
characters, correctly handling wide characters, combining marks, and terminal
escape sequences.
:param text: Text to wrap, may contain terminal sequences.
:param width: Maximum line width in display cells.
:param control_codes: How to handle terminal sequences (see :func:`~.width`).
:param tabsize: Tab stop width for tab expansion.
:param expand_tabs: If True (default), tab characters are expanded
to spaces using ``tabsize``.
:param replace_whitespace: If True (default), each whitespace character
is replaced with a single space after tab expansion. When False,
control whitespace like ``\n`` has zero display width (unlike
:func:`textwrap.wrap` which counts ``len()``), so wrap points
may differ from stdlib for non-space whitespace characters.
:param ambiguous_width: Width to use for East Asian Ambiguous (A)
characters. Default is ``1`` (narrow). Set to ``2`` for CJK contexts.
:param initial_indent: String prepended to first line.
:param subsequent_indent: String prepended to subsequent lines.
:param fix_sentence_endings: If True, ensure sentences are always
separated by exactly two spaces.
:param break_long_words: If True, break words longer than width.
:param break_on_hyphens: If True, allow breaking at hyphens.
:param drop_whitespace: If True (default), whitespace at the beginning
and end of each line (after wrapping but before indenting) is dropped.
Set to False to preserve whitespace.
:param max_lines: If set, output contains at most this many lines, with
``placeholder`` appended to the last line if the text was truncated.
:param placeholder: String appended to the last line when text is
truncated by ``max_lines``. Default is ``' [...]'``.
:param propagate_sgr: If True (default), SGR (terminal styling) sequences
are propagated across wrapped lines. Each line ends with a reset
sequence and the next line begins with the active style restored.
:returns: List of wrapped lines without trailing newlines.
SGR (terminal styling) sequences are propagated across wrapped lines
by default. Each line ends with a reset sequence and the next line
begins with the active style restored::
>>> wrap('\x1b[1;34mHello world\x1b[0m', width=6)
['\x1b[1;34mHello\x1b[0m', '\x1b[1;34mworld\x1b[0m']
Set ``propagate_sgr=False`` to disable this behavior.
Like :func:`textwrap.wrap`, newlines in the input text are treated as
whitespace and collapsed. To preserve paragraph breaks, wrap each
paragraph separately::
>>> text = 'First line.\nSecond line.'
>>> wrap(text, 40) # newline collapsed to space
['First line. Second line.']
>>> [line for para in text.split('\n')
... for line in (wrap(para, 40) if para else [''])]
['First line.', 'Second line.']
.. seealso::
:func:`textwrap.wrap`, :class:`textwrap.TextWrapper`
Standard library text wrapping (character-based).
:class:`.SequenceTextWrapper`
Class interface for advanced wrapping options.
.. versionadded:: 0.3.0
.. versionchanged:: 0.5.0
Added ``propagate_sgr`` parameter (default True).
.. versionchanged:: 0.6.0
Added ``expand_tabs``, ``replace_whitespace``, ``fix_sentence_endings``,
``drop_whitespace``, ``max_lines``, and ``placeholder`` parameters.
Example::
>>> from wcwidth import wrap
>>> wrap('hello world', 5)
['hello', 'world']
>>> wrap('中文字符', 4) # CJK characters (2 cells each)
['中文', '字符']
)rr0r1r<>r<>r2rkrjr<>r<>r<>rqrirl)r,<00>wrap<61>_propagate_sgr)rArr0r1r<>r<>r2rkrjr<>r<>r<>rqrirlr
<00>wrapperr{s rr<>r<>s[<00><00>F"<22><13>#<23><17><1F>-<2D>'<27>%<25>+<2B>1<>)<29>)<29>'<27><1B><1F><06>G<EFBFBD> <14>L<EFBFBD>L<EFBFBD><14> <1E>E<EFBFBD><14><1E>u<EFBFBD>%<25><05> <10>Lr)r#rr<>r<>)rrrrrrr<>r)rrr<>rr<>)"rArrr<>r0r<>r1r<>r<><00>boolr<6C>r<>r2r<>rkrrjrr<>r<>r<>r<>r<>r<>rqr<>riz
int | Nonerlrr
r<>r<>r<>)r<00>
__future__r<00>rer;rU<00>typingrr<00>wcwidthrr?rr<>r <00> sgr_stater
r<><00>escape_sequencesr r r r<00>compiler r%r(r*rVr,r<>rrr<00><module>r<>sO<00><01><04> #<23>
<EFBFBD><0E><0F>,<2C>%<25>#<23>$<24>6<>0<><10>#<23><14>j<EFBFBD><14> <20>R<EFBFBD>Z<EFBFBD>Z<EFBFBD> M<>N<><12><10>0<>
#<23>
]<1F>(<28>.<2E>.<2E>]<1F>@x<11>?F<><19>!<21>$(<28> !<21>!<21>"$<24>&+<2B>"&<26>"&<26>!%<25>!%<25>$<24>#<23>x<11><<3C>x<11><15>x<11><1B>x<11>"<22> x<11>
<1E> x<11> <1D> x<11> <20>x<11> $<24>x<11> <20>x<11> <20>x<11><1F>x<11><1F>x<11><1A>x<11><1D>x<11>)2<>xr