o
    PD©i³.  ã                   @  s†   d dl mZ d dlZd dlmZ d dlmZmZm	Z	m
Z
 dZer&d dlmZ dZG dd„ dejƒZG d	d
„ d
eƒZG dd„ deƒZdS )é    )ÚannotationsN)Ú_HIGHLIGHTSÚ_fix_legacy_win_textÚ	rich_fillÚ	rich_wrapF)ÚLiteralz==GENERATE_USAGE==c                      s  e Zd ZU dZddddddddœZd	ed
< 	 edd… Zded< 	 dK‡ fdd„Ze	dLdd„ƒZ
e
jdMdd„ƒZ
dNd!d"„ZdOd%d&„ZdPd(d)„ZdQd*d+„ZdRd.d/„ZdSd1d2„ZdTd3d4„ZdUd5d6„ZdVd7d8„ZdWd9d:„ZdXd=d>„ZdXd?d@„ZdYdAdB„ZdZdEdF„ZdXdGdH„Zd[dIdJ„Z‡  ZS )\ÚRichHelpFormatterz8An optparse HelpFormatter class that renders using rich.ÚcyanÚdark_orangeÚdefaultÚ	dark_cyanÚboldÚgrey50)úoptparse.argsúoptparse.groupsúoptparse.helpúoptparse.metavarzoptparse.syntaxúoptparse.textúoptparse.progzdict[str, r.StyleType]ÚstylesNz	list[str]Ú
highlightsÚindent_incrementÚintÚmax_help_positionÚwidthú
int | NoneÚshort_firstúbool | Literal[0, 1]ÚreturnÚNonec                   s"   t ƒ  ||||¡ d | _i | _d S ©N)ÚsuperÚ__init__Ú_consoleÚrich_option_strings©Úselfr   r   r   r   ©Ú	__class__© úP/var/www/Datamplify/venv/lib/python3.10/site-packages/rich_argparse/_optparse.pyr"   5   s   
zRichHelpFormatter.__init__ú	r.Consolec                 C  s&   | j d u rtjt | j¡d| _ | j S )N)Útheme)r#   ÚrÚConsoleÚThemer   )r&   r)   r)   r*   Úconsole@   s   
zRichHelpFormatter.consoler0   c                 C  s
   || _ d S r    )r#   )r&   r0   r)   r)   r*   r0   F   s   
Útextúr.RenderableTypeÚstrc                 C  sl   | j  ¡ }| j j|dddd W d   ƒ n1 sw   Y  | ¡ }d dd„ | d¡D ƒ¡}t| j |ƒS )NFTÚ )Ú	highlightÚ	soft_wrapÚendÚ
c                 s  s    | ]}|  ¡ V  qd S r    )Úrstrip)Ú.0Úliner)   r)   r*   Ú	<genexpr>O   s   € z/RichHelpFormatter._stringify.<locals>.<genexpr>)r0   ÚcaptureÚprintÚgetÚjoinÚsplitr   )r&   r1   r=   Úhelpr)   r)   r*   Ú
_stringifyJ   s   ÿzRichHelpFormatter._stringifyÚusageúr.Textc                 C  ó   t dƒ‚©Nzsubclasses must implement©ÚNotImplementedError)r&   rD   r)   r)   r*   Úrich_format_usageR   ó   z#RichHelpFormatter.rich_format_usageÚheadingc                 C  rF   rG   rH   ©r&   rL   r)   r)   r*   Úrich_format_headingU   rK   z%RichHelpFormatter.rich_format_headingc                 C  s`   t | jd| j  dƒ}t d| j ¡}tjj|dd}| jD ]	}|j|dd qt| j	|||ƒS )Né   é   ú r   ©Ústyleú	optparse.©Ústyle_prefix)
Úmaxr   Úcurrent_indentr-   ÚTextÚfrom_markupr   Úhighlight_regexr   r0   )r&   r1   Ú
text_widthÚindentÚ	rich_textr5   r)   r)   r*   Ú_rich_format_textX   s   
z#RichHelpFormatter._rich_format_textÚdescriptionú
str | Nonec                 C  s    |st  ¡ S |  |¡t  d¡ S ©Nr8   ©r-   rY   r_   ©r&   r`   r)   r)   r*   Úrich_format_descriptiona   s   z)RichHelpFormatter.rich_format_descriptionÚepilogc                 C  s*   |st  ¡ S t  d¡|  |¡ t  d¡ S rb   rc   ©r&   rf   r)   r)   r*   Úrich_format_epilogf   s   z$RichHelpFormatter.rich_format_epilogc                 C  s&   |t u r	|  ¡ }n|  |¡}|  |¡S r    )ÚGENERATE_USAGEÚ_generate_usagerJ   rC   )r&   rD   Ú
rich_usager)   r)   r*   Úformat_usagek   s   


zRichHelpFormatter.format_usagec                 C  ó   |   |  |¡¡S r    )rC   rN   rM   r)   r)   r*   Úformat_headingr   ó   z RichHelpFormatter.format_headingc                 C  rm   r    )rC   re   rd   r)   r)   r*   Úformat_descriptionu   ro   z$RichHelpFormatter.format_descriptionc                 C  rm   r    )rC   rh   rg   r)   r)   r*   Úformat_epilogx   ro   zRichHelpFormatter.format_epilogÚoptionúoptparse.Optionc                 C  s–   |j d usJ ‚| jd u s| js|j }n!| jj |j¡}|tju s$|d u r'| j}|j  	| jt
 t|ƒ¡¡}t
jj|dd}| jD ]	}|j|dd q?|S )Nr   rR   rT   rU   )rB   ÚparserÚdefault_tagÚdefaultsr?   ÚdestÚoptparseÚ
NO_DEFAULTÚNO_DEFAULT_VALUEÚreplacer-   Úescaper3   rY   rZ   r   r[   )r&   rr   rB   Údefault_valueÚ	rich_helpr5   r)   r)   r*   Úrich_expand_default{   s   
z%RichHelpFormatter.rich_expand_defaultc           
      C  s
  g }| j | }| j| j d }t|ƒ|kr| d¡ | j}n	| |d ¡ d}| | j¡ | |¡ |jrm|  |¡}t	| j
|| jƒ}| t d| ¡|d  d ¡ t d| j ¡}|dd … D ]}	| ||	 d ¡ q`n|jd dkr}| t d¡¡ n	 t ¡  |¡S )NrO   r8   r   rQ   é   éÿÿÿÿ)r$   Úhelp_positionrX   ÚlenÚappendÚ
set_lengthÚpad_leftrB   r   r   r0   Ú
help_widthr-   rY   Úplainr@   )
r&   rr   ÚresultÚoptsÚ	opt_widthÚindent_firstÚ	help_textÚ
help_linesr]   r;   r)   r)   r*   Úrich_format_option‰   s,   



 ÿz$RichHelpFormatter.rich_format_optionc                 C  rm   r    )rC   r   )r&   rr   r)   r)   r*   Úformat_option¢   ro   zRichHelpFormatter.format_optionrt   úoptparse.OptionParserc                 C  sÚ   |   ¡  d}|jD ]}|  |¡}|j| j|< || j|< t|t|ƒ| j ƒ}q	|   ¡  |j	D ]"}|jD ]}|  |¡}|j| j|< || j|< t|t|ƒ| j ƒ}q2q-|  
¡  |  
¡  t|d | jƒ| _t| j| j dƒ| _d S )Nr   rO   rP   )r]   Úoption_listÚrich_format_option_stringsrˆ   Úoption_stringsr$   rW   rƒ   rX   Úoption_groupsÚdedentÚminr   r‚   r   r‡   )r&   rt   Úmax_lenÚoptÚstringsÚgroupr)   r)   r*   Ústore_option_strings¥   s&   






üz&RichHelpFormatter.store_option_stringsc                   sÀ   |  ¡ r<|jr|j‰n|jd usJ ‚|j ¡ ‰| j dd¡‰‡‡fdd„|jD ƒ}| j dd¡‰ ‡ ‡fdd„|jD ƒ}ndd„ |jD ƒ}dd„ |jD ƒ}| j	rT|| }n|| }t
 d¡ |¡S )	Nz%sr4   c              	     s0   g | ]}t  ˆ¡ t  |d ¡t  ˆ d¡g¡‘qS ©r   r   ©r-   rY   r@   ©r:   Úo)ÚmetavarÚs_delimr)   r*   Ú
<listcomp>Á   ó    
ýÿÿz@RichHelpFormatter.rich_format_option_strings.<locals>.<listcomp>c              	     s0   g | ]}t  ˆ ¡ t  |d ¡t  ˆd¡g¡‘qS r   rž   rŸ   )Úl_delimr¡   r)   r*   r£   È   r¤   c                 S  ó   g | ]	}t j|d d‘qS ©r   rR   ©r-   rY   rŸ   r)   r)   r*   r£   Ï   ó    c                 S  r¦   r§   r¨   rŸ   r)   r)   r*   r£   Ð   r©   z, )Útakes_valuer¡   rw   ÚupperÚ_short_opt_fmtr{   Ú_short_optsÚ_long_opt_fmtÚ
_long_optsr   r-   rY   r@   )r&   rr   Ú
short_optsÚ	long_optsrŠ   r)   )r¥   r¡   r¢   r*   r“   ¹   s&   
üü
z,RichHelpFormatter.rich_format_option_stringsc           	      C  sH  | j du r	tdƒ‚d}g }|  |¡ |¡d }| | d¡¡ |d  | j  ¡ d¡ t|d ƒd }| j jD ]^}|j	t
jkr?q6|jrG|jd n| ¡ }t d	¡ |d
¡}| ¡ ri|jp_|j ¡ }| d¡ |d¡ | d¡ t|d ƒt|ƒ d | jkrŠ| t d| ¡| ¡ q6|d  d¡ |¡ q6| t ¡ ¡ t d¡ |¡S )z0Generate usage string from the parser's actions.Nz*Cannot generate usage if parser is not setz==GENERATED_USAGE_MARKER==r   r8   r   r   r€   ú[r   rQ   r   ú])rt   Ú	TypeErrorrJ   rA   Úextendr„   Úget_prog_namerƒ   r’   rB   rx   ÚSUPPRESS_HELPr­   Úget_opt_stringr-   rY   rª   r¡   rw   r«   r   r@   )	r&   ÚmarkÚusage_linesÚprefixr]   rr   Úopt_strÚoption_usager¡   r)   r)   r*   rj   Ù   s,   

z!RichHelpFormatter._generate_usage©
r   r   r   r   r   r   r   r   r   r   )r   r+   )r0   r+   r   r   )r1   r2   r   r3   ©rD   r3   r   rE   ©rL   r3   r   rE   )r1   r3   r   rE   )r`   ra   r   rE   )rf   ra   r   rE   )rD   r3   r   r3   )rL   r3   r   r3   )r`   ra   r   r3   )rf   ra   r   r3   )rr   rs   r   rE   )rr   rs   r   r3   )rt   r‘   r   r   )r   rE   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r"   Úpropertyr0   ÚsetterrC   rJ   rN   r_   re   rh   rl   rn   rp   rq   r   r   r   rœ   r“   rj   Ú__classcell__r)   r)   r'   r*   r      sD   
 ù		




	









 r   c                      s@   e Zd ZdZ				dd‡ fdd„Zddd„Zddd„Z‡  ZS )ÚIndentedRichHelpFormatterz)Format help with indented section bodies.rO   é   Nr€   r   r   r   r   r   r   r   r   r   c                   ó   t ƒ  ||||¡ d S r    ©r!   r"   r%   r'   r)   r*   r"   ÷   ó   z"IndentedRichHelpFormatter.__init__rD   r3   rE   c                 C  s@   t  d¡}|| }|d  ¡ }t dt|ƒd¡g}tj||dS )Nz
Usage: %s
r4   r   r   )Úspans)rx   Ú_r9   r-   ÚSpanrƒ   rY   )r&   rD   Úusage_templater»   rÎ   r)   r)   r*   rJ      s
   
z+IndentedRichHelpFormatter.rich_format_usagerL   c                 C  s,   t  d| j ¡ |› dd¡}|t  d¡ S )NrQ   ú:r   r8   )r-   rY   rX   r„   )r&   rL   r1   r)   r)   r*   rN     s   z-IndentedRichHelpFormatter.rich_format_heading)rO   rÊ   Nr€   r¾   r¿   rÀ   ©rÁ   rÂ   rÃ   rÄ   r"   rJ   rN   rÈ   r)   r)   r'   r*   rÉ   ô   s    û
	rÉ   c                      s@   e Zd ZdZ				dd‡ fdd„Zddd„Zddd„Z‡  ZS )ÚTitledRichHelpFormatterz,Format help with underlined section headers.r   rÊ   Nr   r   r   r   r   r   r   r   r   c                   rË   r    rÌ   r%   r'   r)   r*   r"     rÍ   z TitledRichHelpFormatter.__init__rD   r3   rE   c                 C  s"   |   t d¡¡}tj |d|d¡S )NÚUsagez  r8   )rN   rx   rÏ   r-   rY   Úassemble)r&   rD   rL   r)   r)   r*   rJ     s   z)TitledRichHelpFormatter.rich_format_usagerL   c                 C  s,   d| j  t|ƒ }tj |dfd|dfd¡S )Nz=-r   r8   )Úlevelrƒ   r-   rY   rÖ   )r&   rL   Ú	underliner)   r)   r*   rN     s   ÿz+TitledRichHelpFormatter.rich_format_heading)r   rÊ   Nr   r¾   r¿   rÀ   rÓ   r)   r)   r'   r*   rÔ     s    û
	rÔ   )Ú
__future__r   rx   Úrich_argparse._lazy_richÚ
_lazy_richr-   Úrich_argparse._commonr   r   r   r   ÚTYPE_CHECKINGÚtypingr   ri   ÚHelpFormatterr   rÉ   rÔ   r)   r)   r)   r*   Ú<module>   s    b