
    i>e              
       *   d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZ er4d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlm Z   G d d      Z! G d d      Z" G d d      Z# G d d      Z$e G d d             Z% e% e$       dddd      Z& e% e!       ddd       Z' e% e#       d!dd"#      Z(d$d%d&d'd(e)d)   d*e*e%d+f   fd,Z+d$d%d&d'd(e)d)   d*e*e%d+f   fd-Z,e G d. d/             Z-e G d0 d1             Z.y)2    N)Iterable)
attrgetter)TYPE_CHECKINGLiteralOptionalUnionevolve)frozen)Box)ConsoleConsoleOptionsRenderableType)PaddingDimensionsPanel)	StyleTypeTable)	HelpEntry)Rendererc                   ,    e Zd ZdZddedz  fdZddZy)NameRendererzRenderer for parameter/command names with optional text wrapping.

    Parameters
    ----------
    max_width : int | None
        Maximum width for wrapping. If None, no wrapping is applied.
    N	max_widthc                     || _         yzInitialize the renderer with formatting options.

        Parameters
        ----------
        max_width : int | None
            Maximum width for wrapping. If None, no wrapping is applied.
        Nr   selfr   s     y/home/jay/workspace/.worktrees/task-2116-dev1/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/help/specs.py__init__zNameRenderer.__init__         #    c                     dj                  |j                        }| j                  |S t        j                  || j                  ddd      }dj                  |      S )az  Render the names column with optional text wrapping.

        Parameters
        ----------
        entry : HelpEntry
            The table entry to render.

        Returns
        -------
        ~rich.console.RenderableType
            Combined names and shorts, optionally wrapped.
            Order: positive_names, positive_shorts, negative_names, negative_shorts
           F   subsequent_indentbreak_on_hyphenstabsize
)joinall_optionsr   textwrapwrap)r   entrytextwrappeds       r    __call__zNameRenderer.__call__*   sY     xx))*>>!K--NN""
 yy!!r#   Nr1   r   returnr   __name__
__module____qualname____doc__intr!   r4    r#   r    r   r      s    ##* #"r#   r   c                   ,    e Zd ZdZddedz  fdZddZy)CommandNameRenderera
  Renderer for command names with aliases in parentheses.

    Displays commands in argparse-style format: ``primary (alias1, alias2)``.

    Parameters
    ----------
    max_width : int | None
        Maximum width for wrapping. If None, no wrapping is applied.
    Nr   c                     || _         yr   r   r   s     r    r!   zCommandNameRenderer.__init__S   r"   r#   c                 *   |j                   r|j                   d   nd}t        |j                   dd       }|r| ddj                  |       d}n|}| j                  |S t	        j
                  || j                  dd	d
      }dj                  |      S )a%  Render command name with aliases in parentheses.

        Parameters
        ----------
        entry : HelpEntry
            The table entry to render.

        Returns
        -------
        ~rich.console.RenderableType
            Primary command name with aliases in parentheses.
        r       Nz (, )r&   Fr'   r(   r,   )r.   listr-   r   r/   r0   )r   r1   primaryaliasesr2   r3   s         r    r4   zCommandNameRenderer.__call__]   s     +0*;*;%##A&u((,-Yb7!3 4A6DD>>!K--NN""
 yy!!r#   r5   r6   r8   r>   r#   r    r@   r@   H   s    ##* # "r#   r@   c                   &    e Zd ZdZddefdZddZy)DescriptionRenderera  Renderer for descriptions with configurable metadata formatting.

    Parameters
    ----------
    newline_metadata : bool
        If True, display metadata (choices, env vars, defaults) on separate lines.
        If False (default), display metadata inline with the description.
    newline_metadatac                     || _         y)zInitialize the renderer with formatting options.

        Parameters
        ----------
        newline_metadata : bool
            If True, display metadata on separate lines instead of inline.
        N)rL   )r   rL   s     r    r!   zDescriptionRenderer.__init__   s     !1r#   c                    ddl m} ddlm} |j                  }| | |             }nHt        ||      s<t        |j                  d      r	 ||      }nddl m}  | |t        |                  }g }|j                  r7dj                  |j                        }|j                   |d| dd             |j                  r7dj                  |j                        }|j                   |d	| dd             |j                  &|j                   |d
|j                   dd             |j                  r|j                   |dd             | j                  r]|r[ddlm} ddl m} g }	|j"                  r|	j                  |j"                         |D ]  }
|	j                  |
        |	r ||	 S  |       S |D ]  }
|j                  |
        |S )a  Render parameter description with metadata annotations.

        Enriches the base description with choices, environment variables,
        default values, and required status.

        Parameters
        ----------
        entry : HelpEntry
            The table entry to render.

        Returns
        -------
        ~rich.console.RenderableType
            Description with appended metadata.
        r   )Text)
InlineText__rich_console__rE   z
[choices: ]dimz
[env var: z
[default: z
[required]zdim red)Group)	rich.textrO   cyclopts.help.inline_textrP   description
isinstancehasattrstrchoicesr-   appendenv_vardefaultrequiredrL   rich.consolerT   primary_renderable)r   r1   rO   rP   rW   metadata_itemschoices_strenv_vars_str	RichGrouprenderablesitems              r    r4   zDescriptionRenderer.__call__   s     	#8''$TV,KK4u((*<=(5 +(c+.>)?@ ==))EMM2K!!$*[M'CU"KL==99U]]3L!!$*\N!'De"LM==$!!$*U]]O1'Eu"MN>>!!$}i"@A   ^7& K --"";#A#AB ' )""4() /:9k*EtvE ' )""4() r#   N)Fr6   )r9   r:   r;   r<   boolr!   r4   r>   r#   r    rK   rK      s    1 1Kr#   rK   c                       e Zd ZdZddZy)AsteriskRendererzRenderer for required parameter asterisk indicator.

    A simple renderer that displays an asterisk (*) for required parameters.
    c                 "    |j                   rdS dS )a,  Render an asterisk for required parameters.

        Parameters
        ----------
        entry : HelpEntry
            The table entry to render.

        Returns
        -------
        ~rich.console.RenderableType
            An asterisk if the entry is required, empty string otherwise.
        *rC   r_   )r   r1   s     r    r4   zAsteriskRenderer.__call__   s     nns,",r#   Nr6   )r9   r:   r;   r<   r4   r>   r#   r    rj   rj      s    
-r#   rj   c                   X   e Zd ZU dZeedf   ed<   	 dZeed<   	 dZeed<   	 dZ	e
d   ed	<   	 dZe
d   ed
<   	 dZe
d   ed<   	 dZed   ed<   	 dZed   ed<   	 dZed   ed<   	 dZedz  ed<   	 dZedz  ed<   	 dZedz  ed<   	 dZedz  ed<   	 dZeed<   	 dZedz  ed<   	 ddZd Zy)
ColumnSpeca  Specification for a single column in a help table.

    Used by :class:`~cyclopts.help.formatters.default.DefaultFormatter` to define
    how individual columns are rendered in help tables. Each column can have its
    own renderer, styling, and layout properties.

    See Also
    --------
    ~cyclopts.help.formatters.default.DefaultFormatter : The formatter that uses these specs.
    ~cyclopts.help.specs.TableSpec : Specification for the entire table.
    ~cyclopts.help.specs.PanelSpec : Specification for the outer panel.
    r   rendererrC   headerfooterNr   header_stylefooter_stylestyleleft)r^   rv   centerrightfulljustifytop)r{   middlebottomverticalellipsis)foldcropr   ignoreoverflowwidth	min_widthr   ratioFno_wrap	highlightc                     t        | j                  t              r t        | j                        |      }n)t	        | j                        r| j                  |      }nd}|dS |S )zRender the cell content based on the renderer type.

        If renderer is a string, retrieves that attribute from the entry.
        If renderer is callable, calls it with the entry.
        NrC   )rX   rp   rZ   r   callable)r   r1   values      r    _render_cellzColumnSpec._render_cell  sU     dmmS)-Jt}}-e4Edmm$MM%(EE]r--r#   c                     t        | fi |S r5   r	   r   kwargss     r    copyzColumnSpec.copy      d%f%%r#   r6   )r9   r:   r;   r<   r   rZ   __annotations__rq   rr   rs   r   rt   ru   rz   r   r~   r   r   r=   r   r   r   r   rh   r   r   r   r>   r#   r    ro   ro      sM    CO$$* FC
 FC
 +/L(;'.
 +/L(;'.
 $(E8K '
 FLGWABK
 49Hg/08
 ?IHg:;H
 E3:
 !IsTz 
 !IsTz 
 E3:
 GT
 "Itd{!
.&r#   ro   rC   rv   rD   zred bold)rp   rq   rz   r   ru   Optioncyan)rp   rq   rz   ru   Descriptionr   )rp   rq   rz   r   consoler   optionsr   entriesr   r7   .c                     t        j                  | j                  dz        }t        t	        |      ddd|      }|t
        fS )a  Get default column specifications for command display.

    Parameters
    ----------
    console : ~rich.console.Console
        Rich console for width calculations.
    options : ~rich.console.ConsoleOptions
        Console rendering options.
    entries : list[HelpEntry]
        Command entries to display.

    Returns
    -------
    tuple[ColumnSpec, ...]
        Column specifications for command table.
    ffffff?r   Commandrv   r   rp   rq   rz   ru   r   )mathceilr   ro   r@   DescriptionColumn)r   r   r   r   command_columns        r    get_default_command_columnsr     sK    & 		'--$./I$y9N 	 r#   c                     t        j                  | j                  dz        }t        t	        |      ddd|      }t        d |D              rt        |t        fS |t        fS )a  Get default column specifications for parameter display.

    Parameters
    ----------
    console : ~rich.console.Console
        Rich console for width calculations.
    options : ~rich.console.ConsoleOptions
        Console rendering options.
    entries : list[HelpEntry]
        Parameter entries to display.

    Returns
    -------
    tuple[ColumnSpec, ...]
        Column specifications for parameter table.
    r   r   r   rv   r   r   c              3   4   K   | ]  }|j                     y wr5   rm   ).0xs     r    	<genexpr>z0get_default_parameter_columns.<locals>.<genexpr>  s     
'!1::
's   )r   r   r   ro   r   anyAsteriskColumnr   )r   r   r   r   name_columns        r    get_default_parameter_columnsr     sn    & 		'--$./I	2K 
'w
''
 	
 
 	
r#   c                      e Zd ZU dZdZedz  ed<   	 dZedz  ed<   	 dZe	d   ed<   	 dZ
e	d   ed<   	 dZe	d   ed<   	 dZe	d   ed	<   	 dZe	d
   ed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZded<   	 dZeed<   	 dZedz  ed<   	 dZedz  ed<   	 dZedz  ed<   	 deedf   ded   dd fd!Zd" Zy)#	TableSpeca$  Specification for table layout and styling.

    Used by :class:`~cyclopts.help.formatters.default.DefaultFormatter` to control
    the appearance of tables that display commands and parameters. This spec defines
    table-wide properties like borders, headers, and padding.

    See Also
    --------
    ~cyclopts.help.formatters.default.DefaultFormatter : The formatter that uses these specs.
    ~cyclopts.help.specs.ColumnSpec : Specification for individual columns.
    ~cyclopts.help.specs.PanelSpec : Specification for the outer panel.
    Ntitlecaptionr   ru   border_stylers   rt   r   boxFshow_headershow_footer
show_linesT	show_edgeexpandpad_edge)r      r   r   r   paddingcollapse_paddingr   r   safe_boxcolumns.r   r   r7   r   c                 L   | j                   }|rt        d |D              rd}i d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	| j                  d
|d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   d| j"                  d| j$                  i}|j'                  |       ddlm}  |di |}|D ]  }|j,                  |j.                  |j                  |j                  |j                  |j0                  |j2                  |j4                  |j                   |j"                  |j6                  |j8                  |j:                  d}	|j<                  |j<                  |	d<    |j>                  di |	  |D ]/  }
|D cg c]  }|jA                  |
       }} |jB                  |  1 |S c c}w )a  Construct and populate a rich.Table.

        Parameters
        ----------
        columns : tuple[ColumnSpec, ...]
            Column specifications defining the table structure.
        entries : Iterable[HelpEntry]
            Table entries to populate the table with.
        **overrides
            Per-render overrides for table settings.

        Returns
        -------
        Table
            A populated Rich Table.
        c              3   6   K   | ]  }|j                      y wr5   )rq   )r   cols     r    r   z"TableSpec.build.<locals>.<genexpr>  s     A#3::~As   Fr   r   ru   r   rs   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rq   rr   rs   rt   ru   rz   r~   r   r   r   r   r   r   r   r>   )"r   allr   r   ru   r   rs   rt   r   r   r   r   r   r   r   r   r   r   r   update
rich.tabler   rq   rr   rz   r~   r   r   r   r   r   
add_columnr   add_row)r   r   r   	overridesr   optsr   tablecolumncol_optser   cellss                r    buildzTableSpec.buildk  s^   0 &&3AAAK
TZZ
t||
 TZZ
 D--	

 D--
 D--
 488
 ;
 4++
 $//
 
 dkk
 
 t||
  5 5
  TZZ!
" #
$ %
( 	I$  	)F -- -- & 3 3 & 3 3!>>"OO"OO#--#--!>>H +(.(8(8%E(x(%	)*  	"A4;<SS%%a(<E<EMM5!	"  =s   4H!c                     t        | fi |S r5   r	   r   s     r    r   zTableSpec.copy  r   r#   ) r9   r:   r;   r<   r   rZ   r   r   ru   r   r   rs   rt   r   r   rh   r   r   r   r   r   r   r   r   r=   r   r   tuplero   r   r   r   r>   r#   r    r   r     s    E3:
 GS4Z
 $(E8K '
 +/L(;'.
 +/L(;'.
 +/L(;'.
  C%
 K
 K
 J
 It
 FD
 Hd
 $0G /
 #d"
 E3:
 !IsTz 
 !HdTk 
Pz3'P +&P
 
Pd&r#   r   c                   ,   e Zd ZU dZdZed   ed<   	 dZed   ed<   	 dZe	d   ed<   	 d	Z
e	d   ed
<   	 dZed   ed<   	 dZed   ed<   	 dZed   ed<   	 dZded<   	 dZeed<   	 dZedz  ed<   	 dZedz  ed<   	 dZedz  ed<   	 dZeed<   	 ddZd Zy)	PanelSpeca"  Specification for panel (outer box) styling.

    Used by :class:`~cyclopts.help.formatters.default.DefaultFormatter` to control
    the appearance of the outer panel that wraps help sections. This spec defines
    the panel's border, title, subtitle, and overall styling.

    See Also
    --------
    ~cyclopts.help.formatters.default.DefaultFormatter : The formatter that uses these specs.
    ~cyclopts.help.specs.TableSpec : Specification for the inner table.
    ~cyclopts.help.specs.ColumnSpec : Specification for individual columns.
    Nr   r   subtitlerv   )rv   rw   rx   title_alignrw   subtitle_alignnoner   ru   r   r   r   )r   rD   r   r   Tr   r   heightr   Fr   c                    | j                   }|ddlm} |}| j                  | j                  | j
                  | j                  || j                  | j                  | j                  | j                  | j                  | j                  d}| j                  | j                  |d<   | j                  | j                  |d<   |j                  |       ddlm}  ||fi |S )zKCreate a Panel around `renderable`. Use kwargs to override spec per render.r   )ROUNDED)r   r   ru   r   r   r   r   r   r   r   r   r   r   r   )r   rich.boxr   r   r   ru   r   r   r   r   r   r   r   r   r   r   
rich.panelr   )r   
renderabler   r   r   r   r   s          r    r   zPanelSpec.build   s     hh;(C  ++"11ZZ --||kkZZkk
 ::! JJDM==$#}}DI$Z(4((r#   c                     t        | fi |S r5   r	   r   s     r    r   zPanelSpec.copyA  r   r#   )r   r   r7   r   )r9   r:   r;   r<   r   r   r   r   r   r   r   ru   r   r   r   r   rh   r   r=   r   r   r   r   r   r>   r#   r    r   r     s#    )-E8$%,
 ,0Hh'(/
 7=K23<
 :BNG56A
 $*E8K )
 +1L(;'0
  C% $*G )
 FD
 E3:
 FC$J
 !HdTk 
 It
)B&r#   r   )/r   r/   collections.abcr   operatorr   typingr   r   r   r   attrsr
   cyclopts.utilsr   r   r   r`   r   r   r   rich.paddingr   r   r   
rich.styler   r   r   cyclopts.helpr   cyclopts.help.protocolsr   r   r@   rK   rj   ro   r   
NameColumnr   rG   r   r   r   r   r   r>   r#   r    <module>r      sw     $  : :  !DD. $ '0." ."b5" 5"p_ _D- -, U& U& U&r 

 ^
	
 (;(=m]cntu !1<@<M
:s?D&
&
!1&
<@<M&

:s?&
R N& N& N&b @& @& @&r#   