o
    i #                     @   sp   d Z ddlZddlZddlmZmZ er$ddlmZmZ ddl	m
Z
mZ deddd	efd
dZG dd dZdS )z5Plain text help formatter for improved accessibility.    N)TYPE_CHECKINGAny)ConsoleConsoleOptions)	HelpEntry	HelpPanelobjconsoler   returnc                 C   s   | du rdS t | dr| j S t | drRddlm} |t |j|j|j	|j
|jdddddd	}| }|j| dd
 W d   n1 sGw   Y  |  S t|  S )a  Extract plain text from Rich renderables.

    Parameters
    ----------
    obj : Any
        Object to convert to plain text.
    console : ~rich.console.Console
        Console for rendering Rich objects.

    Returns
    -------
    str
        Plain text representation.
    N plain__rich_console__r   )r   FT)filewidthheighttab_sizelegacy_windowssafe_boxforce_terminalno_color	highlightmarkupemoji)end)hasattrr   rstriprich.consoler   ioStringIOr   r   r   r   r   captureprintgetstr)r   r	   r   plain_consoler    r$   d/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/help/formatters/plain.py_to_plain_text   s0   



r&   c                   @   s   e Zd ZdZ		d$dededB fddZdd	d
eddfddZ									d%ddZdd	ddde	ddfddZ
dd	ddde	ddfddZdeedf deedf dedd	ddddfd d!Zdeedf deedf dedd	ddf
d"d#ZdS )&PlainFormatterzPlain text formatter for improved accessibility.

    Parameters
    ----------
    indent_width : int
        Number of spaces to indent entries (default: 2).
    max_width : Optional[int]
        Maximum line width for wrapping text.
       Nindent_width	max_widthc                 C   s   || _ || _d| | _d S )N )r)   r*   indent)selfr)   r*   r$   r$   r%   __init__I   s   zPlainFormatter.__init__r	   r   textr
   c                 C   s   |j |ddd dS )z.Print text without any highlighting or markup.F)r   r   N)r    )r-   r	   r/   r$   r$   r%   _print_plainR   s   zPlainFormatter._print_plainoptionsr   panelr   c                 C   s   |j sdS |jr| ||j d |j D ]=}|jr d|jnd}|jr+d|jnd}t|j|}|s7|rR|jdkrH| 	|j|j||| q| 
|j|j|| q|  dS )a@  Format and render a single help panel as plain text.

        Parameters
        ----------
        console : ~rich.console.Console
            Console to render to.
        options : ~rich.console.ConsoleOptions
            Console rendering options.
        panel : HelpPanel
            Help panel to render.
        N:r+   r   	parameter)entriestitler0   namesjoinshortsr&   descriptionformat_format_parameter_entry_format_command_entryr    )r-   r	   r1   r2   entry
names_textshorts_textdescr$   r$   r%   __call__V   s   

zPlainFormatter.__call__usagec                 C   2   |rt ||}|r| || |  dS dS dS )a$  Render the usage line.

        Parameters
        ----------
        console : ~rich.console.Console
            Console to render to.
        options : ~rich.console.ConsoleOptions
            Console rendering options.
        usage : Any
            The usage line (Text or str).
        Nr&   r0   r    )r-   r	   r1   rC   
usage_textr$   r$   r%   render_usage      
zPlainFormatter.render_usager:   c                 C   rD   )a@  Render the description.

        Parameters
        ----------
        console : ~rich.console.Console
            Console to render to.
        options : ~rich.console.ConsoleOptions
            Console rendering options.
        description : Any
            The description (can be various Rich renderables).
        NrE   )r-   r	   r1   r:   	desc_textr$   r$   r%   render_description   rH   z!PlainFormatter.render_descriptionr7   .r9   rA   r>   r   c                 C   s,  t |t | }|sdS g }|r|| |jr'd|j}|d| d |jr9d|j}	|d|	 d |jdurH|d|j d |jrP|d d|}
t|d	kryd|}|
rj| d
|
 }n|}| |t	
|| j
 dS |
r|d  d
|
 }n|d }| |t	
|| j
 dS )a  Format and print a parameter entry.

        Parameters
        ----------
        names : tuple[str, ...]
            Parameter long names.
        shorts : tuple[str, ...]
            Short forms of the parameter.
        desc : str
            Parameter description.
        console : ~rich.console.Console
            Console to print to.
        entry : HelpEntry
            The full help entry with metadata fields.
        N, z
[choices: ]z
[env var: z
[default: z
[required]r+      : r   )listappendchoicesr8   env_vardefaultrequiredlenr0   textwrapr,   )r-   r7   r9   rA   r	   r>   all_options
desc_partschoices_strenv_vars_str	full_descoptions_strr/   r$   r$   r%   r<      s6   




z&PlainFormatter._format_parameter_entryc                 C   s   |rHt |D ]?\}}|dkr:|g}|r|dd|  d|}|r,| d| }	n|}	| |t|	| j q| |t|| j qdS |rhd|}
|rY|
 d| }	n|
}	| |t|	| j dS dS )aW  Format and print a command entry.

        Parameters
        ----------
        names : tuple[str, ...]
            Command long names.
        shorts : tuple[str, ...]
            Short forms of the command.
        desc : str
            Command description.
        console : ~rich.console.Console
            Console to print to.
        r   rK   r+   r   rN   N)	enumeraterP   r8   r0   rV   r,   )r-   r7   r9   rA   r	   inameparts
entry_namer/   
shorts_strr$   r$   r%   r=      s(   

z$PlainFormatter._format_command_entry)r(   N)r	   r   r1   r   r2   r   r
   N)__name__
__module____qualname____doc__intr.   r"   r0   rB   r   rG   rJ   tupler<   r=   r$   r$   r$   r%   r'   >   sz    
	
,




D

r'   )rf   r   rV   typingr   r   r   r   r   cyclopts.helpr   r   r"   r&   r'   r$   r$   r$   r%   <module>   s    1