
    Ki                      t    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
Z G d d      Zy)z5Plain text help formatter for improved accessibility.    N)TYPE_CHECKINGAny)ConsoleConsoleOptions)	HelpEntry	HelpPanelobjconsoler   returnc                    | yt        | d      r| j                  j                         S t        | d      rddlm}  |t        j                         |j                  |j                  |j                  |j                  |j                  ddddd	      }|j                         5 }|j                  | d
       ddd       j                         j                         S t        |       j                         S # 1 sw Y   @xY w)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!   s        j/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/help/formatters/plain.py_to_plain_textr'      s     { sGyy!! s&'(-->>%%"11%% 
 ""$ 	-,	-{{}##%% s8??	- 	-s   #C66C?c            
           e Zd ZdZ	 	 ddededz  fdZddded	dfd
Z	 	 	 	 	 	 	 	 ddZddddde	d	dfdZ
ddddde	d	dfdZdeedf   deddddd	df
dZdeedf   deedf   deddd	df
dZy)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                 4    || _         || _        d|z  | _        y )N )r*   r+   indent)selfr*   r+   s      r&   __init__zPlainFormatter.__init__I   s    
 )"L(    r
   r   textr   c                 ,    |j                  |dd       y)z.Print text without any highlighting or markup.F)r   r   N)r"   )r/   r
   r2   s      r&   _print_plainzPlainFormatter._print_plainR   s    deE:r1   optionsr   c                    |j                   sy|j                  r| j                  ||j                   d       |j                   D ]{  }t        |j                  |      }|j
                  s&|j                  dk(  r| j                  |j
                  |||       T| j                  |j                  |j                  ||       } |j                          y)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:	parameter)entriestitler4   r'   descriptionall_optionsformat_format_parameter_entry_format_command_entrypositive_namespositive_shortsr"   )r/   r
   r5   panelentrydescs         r&   __call__zPlainFormatter.__call__V   s    " }} ;;g%++a'89 ]] 		kE!%"3"3W=D   <<;.001B1BD'SXY ..u/C/CUEZEZ\`bij		k 	r1   usagec                     |rgt        ||      }|rX|j                         j                  d      s| j                  |d|        n| j                  ||       |j	                          yyy)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).
        zUsage:zUsage: N)r'   strip
startswithr4   r"   )r/   r
   r5   rF   
usage_texts        r&   render_usagezPlainFormatter.render_usage}   sg    " 'w7J!'')44X>%%g/EF%%gz:  r1   r;   c                 l    |r2t        ||      }|r#| j                  ||       |j                          yyy)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).
        N)r'   r4   r"   )r/   r
   r5   r;   	desc_texts        r&   render_descriptionz!PlainFormatter.render_description   s9    " &{G<I!!'95  r1   .rD   rC   r   c                 p   |syg }|r|j                  |       |j                  r0dj                  |j                        }|j                  d| d       |j                  r0dj                  |j                        }|j                  d| d       |j                  |j                  d|j                   d       |j
                  r|j                  d       dj                  |      }dj                  |      }	|r|	 d	| }
n|	}
| j                  |t        j                  |
| j                               y)
ax  Format and print a parameter entry.

        Parameters
        ----------
        options : tuple[str, ...]
            All parameter options in display order.
        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-   : )	appendchoicesjoinenv_vardefaultrequiredr4   textwrapr.   )r/   r5   rD   r
   rC   
desc_partschoices_strenv_vars_str	full_descoptions_strr2   s              r&   r>   z&PlainFormatter._format_parameter_entry   s   (  
d# ==))EMM2K
;-q9:==99U]]3L
<.:;==$
5==/;<>>l+HHZ(	 ii(!]"YK0DD'8??4#EFr1   namesshortsc                 &   |rt        |      D ]  \  }}|dk(  rv|g}|r#|j                  ddj                  |      z          dj                  |      }|r| d| }	n|}	| j                  |t	        j
                  |	| j
                               | j                  |t	        j
                  || j
                                y|rNdj                  |      }
|r|
 d| }	n|
}	| j                  |t	        j
                  |	| j
                               yy)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   rP   r-   r   rR   N)	enumeraterS   rU   r4   rY   r.   )r/   r_   r`   rD   r
   inameparts
entry_namer2   
shorts_strs              r&   r?   z$PlainFormatter._format_command_entry   s    , $U+ S46!FETCHHV,<%<=!#J",Rv6)%%gxtT[[/QR %%gxtT[[/QRS &)J$Rv.!gxtT[['IJ r1   )   N)r
   r   r5   r   rB   r   r   N)__name__
__module____qualname____doc__intr0   r$   r4   rE   r   rK   rN   tupler>   r?    r1   r&   r)   r)   >   sU     $)) :);I ;S ;T ;%% "% 	%
 
%N   "  	 
 
 6   "  	 
 
 .3GsCx3G 3G 	3G
 3G 
3Gj-KS#X-K c3h-K 	-K
 -K 
-Kr1   r)   )rl   r   rY   typingr   r   r   r   r   cyclopts.helpr   r   r$   r'   r)   ro   r1   r&   <module>rr      sC    ; 	  %42. .i .C .bSK SKr1   