
    !<iF5                         d Z ddlZddlmZmZm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efd	Z G d
 d          ZdS )zHTML documentation formatter.    N)TYPE_CHECKINGAnyOptional)escape_htmlextract_text)ConsoleConsoleOptions)	HelpEntry	HelpPaneltype_objreturnc                 D   | dS t          | d          r| j                                        }n0t          | d          rt          | d          }nt	          |           }|                    dd                              dd          }|                    d          r|dd	         }d
| dS |                    d
          r|S |                    d          r|dd	         }d| dS |                    d          r|S |                    d          r
|dd         S |S )zFormat a type object into a readable string.

    Parameters
    ----------
    type_obj : Any
        Type object to format.

    Returns
    -------
    str
        Formatted type name.
    N plain__rich_console__z<class 'z'>ztyping.Optional[   z	Optional[]ztyping.Union[   zUnion[ztyping.   )hasattrr   rstripr   strreplace
startswith)r   type_str
inner_typeinner_typess       /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/help/formatters/html.py_format_type_namer       s\    r x!! !>((**	-	.	. !$//x== 
B//77bAAH -.. be_
(:((((			[	)	)  ?++ r"uo&&&&&			X	&	&  9%% |O    c            
       H   e Zd ZdZ	 	 	 	 ddedededz  dee         dz  fd	ZddZ	d
efdZ
ded         ded         ddd
dfdZded         ded         d
dfdZded         ded         d
dfdZded         ded         ded
dfdZded         ded         ded
dfdZdS )HtmlFormattera  HTML documentation formatter.

    Parameters
    ----------
    heading_level : int
        Starting heading level for panels (default: 2).
        E.g., 2 produces "<h2>Commands</h2>", 3 produces "<h3>Commands</h3>".
    include_hidden : bool
        Include hidden commands/parameters in documentation (default: False).
    app_name : str
        The root application name for generating anchor IDs.
    command_chain : list[str]
        The current command chain for generating anchor IDs.
       FNheading_levelinclude_hiddenapp_namecommand_chainc                 r    || _         || _        || _        |pg | _        t	          j                    | _        d S )N)r%   r&   r'   r(   ioStringIO_output)selfr%   r&   r'   r(   s        r   __init__zHtmlFormatter.__init__N   s9     +, *0b{}}r!   r   c                 6    t          j                    | _        dS )z!Reset the internal output buffer.N)r*   r+   r,   r-   s    r   resetzHtmlFormatter.reset[   s    {}}r!   c                 4    | j                                         S )zGet the accumulated HTML output.

        Returns
        -------
        str
            The HTML documentation string.
        )r,   getvaluer0   s    r   
get_outputzHtmlFormatter.get_output_   s     |$$&&&r!   consoler   optionsr	   panelr   c           	      Z   |j         sdS | j                            d           |j        rPt	          t          |j        |                    }| j                            d| j         d| d| j         d           |j        rBt	          t          |j        |                    }|r| j                            d| d           |j        d	k    r| 	                    |j         |           n&|j        d
k    r| 
                    |j         |           | j                            d           dS )a_  Format and render a help panel as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for rendering (used for extracting plain text).
        options : Optional[ConsoleOptions]
            Console rendering options (unused for HTML).
        panel : HelpPanel
            Help panel to render.
        Nz<section class="help-panel">
z<hz class="panel-title">z</hz>
z<div class="panel-description"></div>
command	parameterz</section>
)entriesr,   writetitler   r   r%   descriptionformat_format_command_panel_format_parameter_panel)r-   r5   r6   r7   
title_text	desc_texts         r   __call__zHtmlFormatter.__call__i   sI   " } 	F 	;<<< ; 	u$\%+w%G%GHHJLsD$6ssZss\`\nsssttt  	Z#L1BG$L$LMMI Z""#XY#X#X#XYYY <9$$&&u}g>>>>\[((((@@@>*****r!   r<   r
   c                    |sdS | j                             d           |D ]}g }|j        r|                    |j                   |j        r|                    |j                   | j        r|r|d         }| j        rE| j        |gz   }| j         dd                    |dd                                                    }n| j         d|                                 }d| dt          |           d}t          |          dk    r.d	                    d
 |dd         D                       }	| d	|	 }n#|rd	                    d |D                       nd}t          t          |j        |                    }
| j                             d| d           |
r| j                             d|
            | j                             d           | j                             d           dS )zFormat command entries as HTML.

        Parameters
        ----------
        entries : list[HelpEntry]
            Command entries to format.
        console : Optional[Console]
            Console for text extraction.
        Nz<ul class="commands-list">
r   -   z
<a href="#z"><code>z</code></a>, c              3   <   K   | ]}d t          |           dV  dS <code></code>Nr   .0ns     r   	<genexpr>z6HtmlFormatter._format_command_panel.<locals>.<genexpr>   s4      '\'\Q(HQ(H(H(H'\'\'\'\'\'\r!   c              3   <   K   | ]}d t          |           dV  dS rK   rN   rO   s     r   rR   z6HtmlFormatter._format_command_panel.<locals>.<genexpr>   s4      %V%V1&F{1~~&F&F&F%V%V%V%V%V%Vr!   r   <li><strong>	</strong>: </li>
</ul>
)r,   r=   namesextendshortsr'   r(   joinlowerr   lenr   r?   )r-   r<   r5   entryrY   primary_name
full_chain	anchor_id	name_htmlaliases	desc_htmls              r   rA   z#HtmlFormatter._format_command_panel   sH     	F 	9::: #	* #	*EE{ *U[)))| +U\*** } h h$Qx% J!%!3|n!DJ#'= M M388JqrrN3K3K M M S S U UII $(= A A< A A G G I II cbbK<U<Ubbb	u::>>"ii'\'\RWXYXZXZR['\'\'\\\G#, 9 9 9 9I [`gDII%V%VPU%V%V%VVVVeg	#L1BG$L$LMMILBiBBBCCC 5""#3	#3#3444Ly))))9%%%%%r!   c                 z   |sdS | j                             d           |D ]~}g }|j        r|                    |j                   |j        r|                    |j                   |j        t          |j        |          nd}d}|rut          d |D                       }t          d |D                       }|o|}|r|dv rd |D             d |D             z   }n|r|d	v rd
 |D             d |D             z   }|re|rCt          |          dk    r0dt          |d                    dt          |d                    d}	n"d
                    d |D                       }	nd}	| j                             d|	 d           t          |j        |          }
|
r*| j                             dt          |
                      g }|j        r|                    d           |j        r=d
                    d |j        D                       }|                    d| d           ||r|dv rKt          d |D             |r|d         nd          }|                    dt          |           d           n|d	v rAt          d  |D             d!          }|                    dt          |           d           nM|                    dt          |           d           n&|                    dt          |           d           |j        r=d
                    d" |j        D                       }|                    d#| d           |r1| j                             d$d
                    |           d           | j                             d%           | j                             d&           dS )'zFormat parameter entries as HTML.

        Parameters
        ----------
        entries : list[HelpEntry]
            Parameter entries to format.
        console : Optional[Console]
            Console for text extraction.
        Nz<ul class="parameters-list">
Fc              3   l   K   | ]/}|                     d            o|                     d          V  0dS --no-z--Nr   rO   s     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   sC      "c"cXYq||G'<'<#<#SdASAS"c"c"c"c"c"cr!   c              3   @   K   | ]}|                     d           V  dS ri   Nrj   rO   s     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   s.      "H"HQ1<<#8#8"H"H"H"H"H"Hr!   )Trueenabledc                 <    g | ]}|                     d           |S ri   rj   rO   s     r   
<listcomp>z9HtmlFormatter._format_parameter_panel.<locals>.<listcomp>   s)    GGG1g1F1FGQGGGr!   c                 <    g | ]}|                     d           |S rp   rj   rO   s     r   rq   z9HtmlFormatter._format_parameter_panel.<locals>.<listcomp>   s@     K K KW0E0EKK K Kr!   )Falsedisabledc                 <    g | ]}|                     d           |S rp   rj   rO   s     r   rq   z9HtmlFormatter._format_parameter_panel.<locals>.<listcomp>   s)    KKK1Q\\'5J5JKQKKKr!   c                 <    g | ]}|                     d           |S rp   rj   rO   s     r   rq   z9HtmlFormatter._format_parameter_panel.<locals>.<listcomp>   s@     O O OALL,A,AOO O Or!   r$   rL   r   z</code>, <code>rH   rM   rI   c              3   <   K   | ]}d t          |           dV  dS rK   rN   rO   s     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>   s4      )Z)Zq*J;q>>*J*J*J)Z)Z)Z)Z)Z)Zr!   r   rT   rU   rV   z=<span class="metadata-item metadata-required">Required</span>c              3   V   K   | ]$}d t          t          |                     dV  %dS rK   )r   r   )rP   cs     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>  s=      'e'eRS(MSVV1D1D(M(M(M'e'e'e'e'e'er!   zZ<span class="metadata-item metadata-choices"><span class="metadata-label">choices:</span> z</span>c              3   n   K   | ]0}|                     d           |                     d          ,|V  1dS rh   rj   rO   s     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>  sE      bb1Q\\'5J5Jbq||\`OaOabQbbbbbbr!   z--flagz`<span class="metadata-item metadata-default"><span class="metadata-label">default:</span> <code>z</code></span>c              3   D   K   | ]}|                     d           |V  dS rl   rj   rO   s     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>&  s3      -X-XA!,,wBWBW-Xa-X-X-X-X-X-Xr!   z	--no-flagc              3   <   K   | ]}d t          |           dV  dS rK   rN   )rP   es     r   rR   z8HtmlFormatter._format_parameter_panel.<locals>.<genexpr>5  s4      $]$]!%Ek!nn%E%E%E$]$]$]$]$]$]r!   zR<span class="metadata-item metadata-env"><span class="metadata-label">env:</span> z!<span class="parameter-metadata">rW   rX   )r,   r=   rY   rZ   r[   defaultr   anyr^   r   r\   r?   requiredappendchoicesnextenv_var)r-   r<   r5   r_   rY   default_stris_bool_flaghas_positivehas_negativerc   descmetadata_itemschoices_strpositive_flagnegative_flagenv_htmls                   r   rB   z%HtmlFormatter._format_parameter_panel   s~     	F 	;<<< d	* d	*EE{ *U[)))| +U\*** CH-B[,u}g>>>aeK L  ""c"c]b"c"c"ccc""H"H%"H"H"HHH+< 	K3F$F$FGGGGG K K#(K K K EE " k5J&J&JKKKKK O O#(O O O E
   [CJJ!OO mU1X)>)> m m{[`ab[cOdOd m m mII $		)Z)ZTY)Z)Z)Z Z ZII	 LBiBBBCCC   17;;D =""#;D(9(9#;#;<<<  N ~ g%%&efff } "ii'e'eW\Wd'e'e'eee%% Fq|  F  F  F  
 & "&999(,bbbbb(-;E!HH8) ) '-- j  @K  LY  @Z  @Z  j  j  j    %(===(,-X-X-X-X-XZe(f(f&-- j  @K  LY  @Z  @Z  j  j  j    '-- h  @K  LW  @X  @X  h  h  h    #)) d  |G  HS  |T  |T  d  d  d  
 } 99$]$]u}$]$]$]]]%%ziqzzz  
  i""#grww~G^G^#g#g#ghhhLy))))9%%%%%r!   usagec                     |rst          t          ||                    }|rV| j                            d           | j                            d| d           | j                            d           dS dS dS )a.  Render the usage line as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        usage : Any
            The usage line content.
        z<div class="usage-block">
z<pre class="usage">z</pre>
r9   Nr   r   r,   r=   )r-   r5   r6   r   
usage_texts        r   render_usagezHtmlFormatter.render_usageB  s    "  	/$\%%A%ABBJ /""#@AAA""#M#M#M#MNNN"":.....	/ 	// /r!   r?   c                     |r?t          t          ||                    }|r"| j                            d| d           dS dS dS )a6  Render the description as HTML.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        description : Any
            The description content.
        z<div class="description">r9   Nr   )r-   r5   r6   r?   rD   s        r   render_descriptionz HtmlFormatter.render_descriptionZ  sm    "  	T#Lg$F$FGGI T""#Ry#R#R#RSSSSS	T 	TT Tr!   )r$   FNN)r   N)__name__
__module____qualname____doc__intboolr   listr.   r1   r4   r   rE   rA   rB   r   r   r    r!   r   r#   r#   >   s        " $#*.% %% % *	%
 Cy4'% % % %% % % %'C ' ' ' '(+)$(+ *+(+ 	(+
 
(+ (+ (+ (+T5&T+-> 5&R[I\ 5&ae 5& 5& 5& 5&nv&tK/@ v&8T]K^ v&cg v& v& v& v&p/)$/ *+/ 	/
 
/ / / /0T)$T *+T 	T
 
T T T T T Tr!   r#   )r   r*   typingr   r   r   cyclopts._markupr   r   rich.consoler   r	   cyclopts.helpr
   r   r   r    r#   r   r!   r   <module>r      s    # # 				 / / / / / / / / / / 6 6 6 6 6 6 6 6 34444444422222222- - - - - -`pT pT pT pT pT pT pT pT pT pTr!   