
    ^h                         S r SSKrSSKrSSKrSSKrSSKJr  \R                  S:X  a  SrOSrSS jr	S r
SS	 jrS
 rS rSS jrSS jrSS jrSS jrg)z~
Utilities for working with strings and text.

Inheritance diagram:

.. inheritance-diagram:: IPython.utils.text
   :parts: 3
    N)	Formatterwin32z	%B %d, %Yz
%B %-d, %Yc                 b   U c  gSU-  SU-  -   nU(       a&  [         R                  " S[         R                  5      nO%[         R                  " S[         R                  5      n[         R                  " XTU 5      nUR	                  [
        R                  U-   5      (       a  US[        U5      *  $ U$ )aV  Indent a string a given number of spaces or tabstops.

indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.

Parameters
----------

instr : basestring
    The string to be indented.
nspaces : int (default: 4)
    The number of spaces to be indented.
ntabs : int (default: 0)
    The number of tabs to be indented.
flatten : bool (default: False)
    Whether to scrub existing indentation.  If True, all lines will be
    aligned to the same indentation.  If False, existing indentation will
    be strictly increased.

Returns
-------

str|unicode : string indented by ntabs and nspaces.

N	 z^\s*^)recompile	MULTILINEsubendswithoslineseplen)instrnspacesntabsflattenindpatoutstrs          O/home/james-whalen/.local/lib/python3.13/site-packages/ipython_genutils/text.pyindentr      s    2 }
u*S[
 Cjj",,/jjr||,VVCe$Frzz#~&&jCy!!    c                     U R                  S5      (       a  [        R                  " U 5      $ U R                  SS5      n[	        U5      S:X  a  [        R                  " U 5      $ Uu  p#[        R                  " U5      nSR                  X#/5      $ )zEquivalent of textwrap.dedent that ignores unindented first line.

This means it will still dedent strings like:
'''foo
is a bar
'''

For use in wrap_paragraphs.

   )
startswithtextwrapdedentsplitr   join)textsplitsfirstrests       r   r    r    ?   su     tt$$ ZZQF
6{at$$KE??4 D99e]##r   c                    [         R                  " S[         R                  5      n[        U 5      R	                  5       n UR                  U 5      SSS2   n/ n[         R                  " S[         R                  5      nU H<  nUR                  U5      c  [        R                  " Xa5      nUR                  U5        M>     U$ )zWrap multiple paragraphs to fit a specified width.

This is equivalent to textwrap.wrap, but with support for multiple
paragraphs, as separated by empty lines.

Returns
-------

list of complete paragraphs, wrapped to fill `ncols` columns.
z
\n(\s*\n)+N   z\n\s+)
r	   r
   r   r    stripr!   searchr   fillappend)r#   ncolsparagraph_re
paragraphsout_ps	indent_reps          r   wrap_paragraphsr3   Z   s     ::mR\\:L$<D##D)#A#.JF

8R\\2I A&a'Aa  Mr   c                 2    [         R                  " SSU 5      $ )zl
Remove ansi escape codes from text.

Parameters
----------
source : str
    Source to remove the ansi from
z\033\[(\d|;)+?m )r	   r   )sources    r   
strip_ansir7   t   s     66$b&11r   c              #   V   #    [        S[        U 5      U5       H  nXX!-    v   M     g7f)z'Yield successive n-sized chunks from l.r   N)ranger   )lnis      r   _chunksr=      s'     1c!fa !#h !s   ')c           
         [        S[        U 5      S-   5       HK  n[        [        [        [        X5      5      5      n[        U5      n[        U5      nXQUS-
  -  -   U::  d  MK    O   WUS-
  (       a  UW-
  US-
  -  OSWWS.$ )z4Calculate optimal info to columnize a list of stringr   r   )columns_numbersoptimal_separator_widthrows_numberscolumns_width)r9   r   listmapmaxr=   sum)rlistseparator_sizedisplaywidthnrowchk	sumlengthr-   s          r   _find_optimalrM      s    aUA&3s75/01H	CU1W--= ' !&OTVWx|i'?%'&J^_!! r   c                 ,    U[        U 5      :  a  U$ X   $ )z2return list item number, or default if don't exist)r   )mylistr<   defaults      r   _get_or_defaultrQ      s    CKyr   c                    [        [        [        [        U 5      5      /UQ70 UD6nUS   US   pe[	        U5       VVs/ s H-  n[	        U5       Vs/ s H  n[        XU-  U-   US9PM     snPM/     snnU4$ s  snf s  snnf )al  Returns a nested list, and info to columnize items

Parameters
----------

items
    list of strings to columize
empty : (default None)
    default value to fill list if needed
separator_size : int (default=2)
    How much caracters will be used as a separation between each columns.
displaywidth : int (default=80)
    The width of the area onto wich the columns should enter

Returns
-------

strings_matrix

    nested list of string, the outer most list contains as many list as
    rows, the innermost lists have each as many element as colums. If the
    total number of elements in `items` does not equal the product of
    rows*columns, the last element of some lists are filled with `None`.

dict_info
    some info to make columnize easier:

    columns_numbers
      number of columns
    rows_numbers
      number of rows
    columns_width
      list of with of each columns
    optimal_separator_width
      best separator width between columns

Examples
--------
::

    In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
       ...: compute_item_matrix(l,displaywidth=12)
    Out[1]:
        ([['aaa', 'f', 'k'],
        ['b', 'g', 'l'],
        ['cc', 'h', None],
        ['d', 'i', None],
        ['eeeee', 'j', None]],
        {'columns_numbers': 3,
        'columns_width': [5, 1, 1],
        'optimal_separator_width': 2,
        'rows_numbers': 5})
rA   r?   )rP   )rM   rC   rD   r   r9   rQ   )	itemsemptyargskwargsinforJ   ncolr<   cs	            r   compute_item_matrixrZ      s    l c#uo.@@@Dn%t,='>$_dei_jl_jZ[dU1ufQh>U_jlnrssUls   A=A8+A=8A=c                    ^^ U (       d  g[        U [        T5      US9u  nmU Vs/ s H  n[        SU5      PM     nnUU4S jnSR                  [	        Xe5      5      S-   $ s  snf )ao  Transform a list of strings into a single string with columns.

Parameters
----------
items : sequence of strings
    The strings to process.

separator : str, optional [default is two spaces]
    The string that separates columns.

displaywidth : int, optional [default is 80]
    Width of the display in number of characters.

Returns
-------
The formatted string.
r   )rH   rI   Nc           
         > TR                  [        U TS   5       VVs/ s H  u  pUR                  US5      PM     snn5      $ s  snnf )NrB   r   )r"   zipljust)xywrW   	separators      r   <lambda>columnize.<locals>.<lambda>   s;    y~~C4P_K`Da&bDaDA3Da&bc&bs   A
)rZ   r   filterr"   rD   )rS   rb   rI   matrixr_   fmatrixsjoinrW   s    `     @r   	columnizeri      s_    $ &uS^ZfgLFD(./1vdAG/cE99S()$.. 0s   A")   r   F)P   )r(   rk   )N)z  rk   )__doc__r   r	   sysr   stringr   platformdate_formatr   r    r3   r7   r=   rM   rQ   rZ   ri    r   r   <module>rr      sc    
 	 
   <<7KK$N$64	2 8tv/r   