
    @g^&                         d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ dZd Zd	 Z d
 Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(ddZ)y)aN  
Usage: humanfriendly [OPTIONS]

Human friendly input/output (text formatting) on the command
line based on the Python package with the same name.

Supported options:

  -c, --run-command

    Execute an external command (given as the positional arguments) and render
    a spinner and timer while the command is running. The exit status of the
    command is propagated.

  --format-table

    Read tabular data from standard input (each line is a row and each
    whitespace separated field is a column), format the data as a table and
    print the resulting table to standard output. See also the --delimiter
    option.

  -d, --delimiter=VALUE

    Change the delimiter used by --format-table to VALUE (a string). By default
    all whitespace is treated as a delimiter.

  -l, --format-length=LENGTH

    Convert a length count (given as the integer or float LENGTH) into a human
    readable string and print that string to standard output.

  -n, --format-number=VALUE

    Format a number (given as the integer or floating point number VALUE) with
    thousands separators and two decimal places (if needed) and print the
    formatted number to standard output.

  -s, --format-size=BYTES

    Convert a byte count (given as the integer BYTES) into a human readable
    string and print that string to standard output.

  -b, --binary

    Change the output of -s, --format-size to use binary multiples of bytes
    (base-2) instead of the default decimal multiples of bytes (base-10).

  -t, --format-timespan=SECONDS

    Convert a number of seconds (given as the floating point number SECONDS)
    into a human readable timespan and print that string to standard output.

  --parse-length=VALUE

    Parse a human readable length (given as the string VALUE) and print the
    number of metres to standard output.

  --parse-size=VALUE

    Parse a human readable data size (given as the string VALUE) and print the
    number of bytes to standard output.

  --demo

    Demonstrate changing the style and color of the terminal font using ANSI
    escape sequences.

  -h, --help

    Show this message and exit.
    N)Timerformat_lengthformat_numberformat_sizeformat_timespanparse_length
parse_size)format_pretty_tableformat_smart_table)
ANSI_COLOR_CODESANSI_TEXT_STYLESHIGHLIGHT_COLOR
ansi_strip	ansi_wrapenable_ansi_supportfind_terminal_sizeoutputusagewarning)Spinner)demonstrate_256_colorsdemonstrate_ansi_formattingmainprint_formatted_lengthprint_formatted_numberprint_formatted_sizeprint_formatted_tableprint_formatted_timespanprint_parsed_lengthprint_parsed_sizerun_commandc                     t                	 t        j                  t        j                  dd dg d      \  } }g }d}d}t        d  D              }| D ]  \  }}|dv r|}|d	k(  r*|j                  t        j                  t        |             =|d
k(  r*|j                  t        j                  t        |             l|dv r*|j                  t        j                  t                     |dv r*|j                  t        j                  t        |             |dv r*|j                  t        j                  t        |             |dv r,|j                  t        j                  t         ||             &|dk(  rd}/|dv r+|j                  t        j                  t"        |             ^|dk(  r|j                  t$               z|dv st'        t(                y |r)|j                  t        j                  t*        |             |st'        t(               y|D ]	  }	 |	         y# t        $ r,}t        d|       t        j                  d       Y d}~(d}~ww xY w)z9Command line interface for the ``humanfriendly`` program.   Nzcd:l:n:s:bt:h)zrun-commandzformat-tablez
delimiter=zformat-length=zformat-number=zformat-size=binaryzformat-timespan=zparse-length=zparse-size=demohelpz	Error: %sFc              3   *   K   | ]  \  }}|d v   yw))z-bz--binaryN ).0ovs      F/var/www/openai/venv/lib/python3.12/site-packages/humanfriendly/cli.py	<genexpr>zmain.<locals>.<genexpr>   s     =WTQ((Ws   )z-dz--delimiterz--parse-sizez--parse-length)z-cz--run-command)z-lz--format-length)z-nz--format-number)z-sz--format-sizez--format-tableT)z-tz--format-timespanz--demo)z-hz--help)r   getoptsysargv	Exceptionr   exitanyappend	functoolspartialr    r   r!   r   r   r   r   r   r   __doc__r   )
options	argumentseactions	delimitershould_format_tabler$   optionvaluer6   s
             r,   r   r      s   #]]388AB< K
  GI=W==F **I~%NN9,,->FG''NN9,,-@%HI..NN9,,[)DE00NN9,,-CUKL00NN9,,-CUKL..NN9,,-A5&QR''"&22NN9,,-EuMNxNN67'''N/ !0 y(()>	JKg	 I  Qs   -H1 1	I&:!I!!I&c                    t               }ddj                  t        t        j                  |             z  }t        ||      5 }t        j                  |       }	 |j                          |j                          |j                         n2	 ddd       t        j                  j                         y# 1 sw Y   )xY w)zHRun an external command and show a spinner while the command is running.zWaiting for command: %s )labeltimerN)r   joinmappipesquoter   
subprocessPopenstepsleeppollr/   r2   
returncode)command_linerC   spinner_labelspinnerprocesss        r,   r!   r!      s    GE-U[[,9W0XXM	}E	2g""<0LLNMMO||~)	   
3 HHW  
3	2s   A	B66B?c                     d| v rt        t        t        |                    yt        t        t        |                    y)zPrint a human readable length..N)r   r   floatintr?   s    r,   r   r      s+    
e|}U5\*+}SZ()    c                 >    t        t        t        |                    y)z/Print large numbers in a human readable format.N)r   r   rT   rV   s    r,   r   r      s    
=u&'rW   c                 B    t        t        t        |       |             y)zPrint a human readable size.)r$   N)r   r   rU   )r?   r$   s     r,   r   r      s    
;s5z&12rW   c                     g }t         j                  D ]2  }|j                         }|j                  |j	                  |              4 t        t        |             y)z8Read tabular data from standard input and print a table.N)r/   stdinrstripr4   splitr   r
   )r<   datalines      r,   r   r      sE    D		{{}DJJy)*  t$%rW   c                 >    t        t        t        |                    y)z Print a human readable timespan.N)r   r   rT   rV   s    r,   r   r      s    
?5<()rW   c                 ,    t        t        |              y)z=Parse a human readable length and print the number of metres.N)r   r   rV   s    r,   r   r      s    
<rW   c                 ,    t        t        |              y)z?Parse a human readable data size and print the number of bytes.N)r   r	   rV   s    r,   r    r       s    
:erW   c                     t        dt        dd             ddg} | j                  t        j                                t        |       D ]R  }t        t              }|dk7  rd||<   |j                  dd	      j                         }t        d
t        |fi |       T dD ]  \  }}dt               fdt        d      fg}|dk7  r|j                  ddt        d      f       t        dt        d|z  d      z         t        t        t        t        j                               D 	cg c]R  }|g|D 	cg c]>  \  }}	t        |dk7  rdndfi t        t        |	j                               ||fgz         @ c}	}z   T c}	}}dg|D 	cg c]  \  }}	|j                          c}	}z                 t        ddd       t        ddd       t        ddd       t        dd d!       y"c c}	}w c c}	}}w c c}	}w )#z-Demonstrate the use of ANSI escape sequences.z%szText styles:Tboldnormalbrightcolor_rA   z - %s))ri   zForeground colors)
backgroundzBackground colors)rg   rk   r   faint)rl   z
%s%s:XXXXXXz      Color)column_names   zstandard colors      zhigh-intensity colors      z
216 colors      zgray scale colorsN)r   r   extendr   keyssorteddictr   replace
capitalizeinsertr   r   listitemsr   )
styles
style_namer8   style_label
color_typecolor_labelintensities
color_namerB   kws
             r,   r   r      s    4>56!F
MM"'')*Vn
_-!"&GJ ((c2==?w	+99: %$I
K tvt4()
 %q7Dt,<"=>v	%+"5DAAB! !''7'<'<'> ?#
 !@* L $/	 $/ieR  *l :H4
+
J/G.HHI $/	 
 !@#
 !	0;%
0;95"E%
 
	 		$I( 1a!231b"9:2sL13%89#
%
s   ,G58AG/;G5G</G5c                 n   d}|r|d|z  z  }t        dt        d|z  d      z          dj                  d t        | |d	z         D              }t	               \  }}|t        t        |            k\  rt        |       yt        t        |            d	z   }t        ||z        }t        | |d	z         D 	cg c]'  }	t        t        |	      j                  |      |	
      ) }
}	t        dt        |
      |      D 	cg c]
  }	|
|	|	|z     }}	t        dj                  d |D                     yc c}	w c c}	w )z#Demonstrate 256 color mode support.z256 color modez (%s)
rm   Trd    c              3   N   K   | ]  }d t        t        |      |      z     yw)rA   rh   N)r   str)r)   ns     r,   r-   z)demonstrate_256_colors.<locals>.<genexpr>  s!     TOq#	#a& ::Os   #%r#   rh   r   c              3   >   K   | ]  }d j                  |        yw)r   N)rD   )r)   bs     r,   r-   z)demonstrate_256_colors.<locals>.<genexpr>#  s     4VVs   N)
r   r   rD   ranger   lenr   r   rU   rjust)ijgrouprB   single_linelinescolumnswidthcolors_per_liner   colorsblockss               r,   r   r     s    E5 
4)EEM556 ''TE!QQRUOTTK')NE7#j-..{ CFago.CHAPQE?S?a)CFLL/q9?S9>q#f+9_`9_A&1./9_`tyy4V445 T`s   4,D-:D2)N)*r7   r5   r.   rF   rH   r/   humanfriendlyr   r   r   r   r   r   r	   humanfriendly.tablesr
   r   humanfriendly.terminalr   r   r   r   r   r   r   r   r   r   humanfriendly.terminal.spinnersr   __all__r   r!   r   r   r   r   r   r   r    r   r   r(   rW   r,   <module>r      s   FR     
   I   4.b!*(
3
&*
 

$:N6rW   