o
    Rh^&                     @   s   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d	 Zd
d Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(dddZ)dS )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            
   
   C   s  t   zttjdd dg d\} }W n ty1 } ztd| td W Y d}~nd}~ww g }d}d}tdd | D }| D ]\}}|d	v rN|}qC|d
kr\|t	
t| qC|dkrj|t	
t| qC|dv rx|t	
t| qC|dv r|t	
t| qC|dv r|t	
t| qC|dv r|t	
t|| qC|dkrd}qC|dv r|t	
t| qC|dkr|t qC|dv rtt  dS qC|r|t	
t| |stt dS |D ]}	|	  qdS )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                 s   s    | ]	\}}|d v V  qdS ))z-bz--binaryN ).0ovr%   r%   S/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/humanfriendly/cli.py	<genexpr>   s    zmain.<locals>.<genexpr>)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valuer3   r%   r%   r)   r      sZ   $
r   c                 C   s   t  }ddttj|  }t||d}t| }	 |  |	  |
 dur*nqW d   n1 s5w   Y  t|j dS )zHRun an external command and show a spinner while the command is running.zWaiting for command: %s )labeltimerTN)r   joinmappipesquoter   
subprocessPopenstepsleeppollr,   r/   
returncode)command_liner?   spinner_labelspinnerprocessr%   r%   r)   r       s   
r    c                 C   s0   d| v rt tt|  dS t tt|  dS )zPrint a human readable length..N)r   r   floatintr<   r%   r%   r)   r      s   r   c                 C      t tt|  dS )z/Print large numbers in a human readable format.N)r   r   rO   rQ   r%   r%   r)   r         r   c                 C   s   t tt| |d dS )zPrint a human readable size.)r"   N)r   r   rP   )r<   r"   r%   r%   r)   r      s   r   c                 C   s8   g }t jD ]}| }|||  qtt| dS )z8Read tabular data from standard input and print a table.N)r,   stdinrstripr1   splitr   r	   )r9   dataliner%   r%   r)   r      s
   
r   c                 C   rR   )z Print a human readable timespan.N)r   r   rO   rQ   r%   r%   r)   r      rS   r   c                 C      t t|  dS )z=Parse a human readable length and print the number of metres.N)r   r   rQ   r%   r%   r)   r         r   c                 C   rY   )z?Parse a human readable data size and print the number of bytes.N)r   r   rQ   r%   r%   r)   r      rZ   r   c                     s>  t dtddd ddg} | t  t| D ]"}ttd}|dkr'd||< |dd		 }t d
t|fi | qdD ]G\ }dt fdtddfg dkr\
ddtddf t dtd| dd  t t fddtt D dgdd D  d q=tddd tddd tddd td d!d" d#S )$z-Demonstrate the use of ANSI escape sequences.z%szText styles:Tboldnormalbrightcolor_r=   z - %s))r`   zForeground colors)
backgroundzBackground colors)r^   rb   r   faint)rc   z
%s%s:c                    s&   g | ]  g fd dD  qS )c              	      sB   g | ]\}}t d krdndfi tt|  fg qS )rb   XXXXXXz      )r   dictlistitemsr&   r>   kw)
color_name
color_typer%   r)   
<listcomp>   s    z:demonstrate_ansi_formatting.<locals>.<listcomp>.<listcomp>r%   )r&   rl   intensities)rk   r)   rm      s    z/demonstrate_ansi_formatting.<locals>.<listcomp>Colorc                 S   s   g | ]\}}|  qS r%   )
capitalizeri   r%   r%   r)   rm     s    )column_names   zstandard colors      zhigh-intensity colors      z
216 colors      zgray scale colorsN)r   r   extendr   keyssortedrf   r   replacerq   insertr
   r   r   )styles
style_namer5   style_labelcolor_labelr%   rn   r)   r      s6   



r   c                    s   d}|r
|d| 7 }t dtd| dd  ddd	 t| |d
 D }t \}}|tt|kr8t | dS tt|d
 t| fddt| |d
 D   fddtdt D }t ddd	 |D  dS )z#Demonstrate 256 color mode support.z256 color modez (%s)
rd   Tr[    c                 s   s$    | ]}d t t||d V  qdS )r=   r_   N)r   strr&   nr%   r%   r)   r*     s   " z)demonstrate_256_colors.<locals>.<genexpr>r!   c                    s"   g | ]}t t| |d qS )r_   )r   r   rjustr   )widthr%   r)   rm   !  s   " z*demonstrate_256_colors.<locals>.<listcomp>c                    s   g | ]
} ||  qS r%   r%   r   )colorscolors_per_liner%   r)   rm   "  s    r   c                 s   s    | ]}d  |V  qdS )r   N)r@   )r&   br%   r%   r)   r*   #  s    N)	r   r   r@   ranger   lenr   r   rP   )ijgroupr>   single_linelinescolumnsblocksr%   )r   r   r   r)   r     s   
 r   )N)*r4   r2   r+   rB   rD   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%   r%   r%   r)   <module>   s,   I$	01	'