
    Ki                         d Z ddlZddlmZ ej                  dk\  rddlmZ nddlmZ erddlmZ ddl	m
Z
  G d d	      Zy)
z@InlineText class for rich text rendering with appended metadata.    N)TYPE_CHECKING)      )Self)RenderableTypeTextc                   \    e Zd ZddddZeddddedz  deded	ed
ef
d       ZddZ	d Z
y)
InlineTextFforce_empty_endc                .    || _         g | _        || _        y N)primary_renderabletextsr   )selfr   r   s      e/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/help/inline_text.py__init__zInlineText.__init__   s    "4
.    )r   show_errorscontentNformatr   r   returnc                D   |ddl m}  |d      }n|dk(  rddl m}  ||j                               }nc|dv rddlm}  ||      }nP|dv rdd	lm} dd
lm}	  |	|      }
 ||
|      }n-|dk(  rddl m}  |j                  |      }nt        d| d       | ||      S )Nr   r    end	plaintext)markdownmd)Markdown)restructuredtextrst)RestructuredText)process_sphinx_directives)r   richzUnknown help_format ""r   )	rich.textr	   rstriprich.markdownr!   rich_rstr$   cyclopts.help.rst_preprocessorr%   from_markup
ValueError)clsr   r   r   r   r	   r   r!   r$   r%   processed_contents              r   from_formatzInlineText.from_format   s     ?&!%"{"&!%gnn&6!7)).!)'!2221P 9' B!12CQ\!]v&!1!1!1'!:4VHA>??%GGr   c                 :    | j                   j                  |       y r   )r   append)r   texts     r   r3   zInlineText.append;   s    

$r   c              #     K   ddl m} ddlm} | j                  s| j
                  sy g g }}|j                  | j                  |      D ]:  }|j                  dk(  r|j                  ||gz          g }*|j                  |       < |r|j                  |       |s@| j
                  r3 |j                  | j
                   }|j                  ||      E d {    y |d d D ]  }	|	D ]  }|   |rY|d   }
|
xr |
d   j                  dk(  }|r|
j                         nd }|
rA|
d   } ||j                  j                         |j                  |j                        }||
d<    |dd      }|
D ]5  }|j                  s|j                  |j                  |j                         7  |d	      }| j
                  D ]  }|r||z  }||z  } t        |j                  ||            }| j                  r9|d   }|r2|j                  j!                  d      s|j                   |d             |r|j                  |       |E d {    y y 7 x7 	w)
Nr   )Segmentr   
)stylecontrolr   r    )rich.segmentr6   r(   r	   r   r   renderr4   r3   assemblepopr)   r9   r:   listr   endswith)r   consoleoptionsr6   r	   lines_of_segmentscurrent_linesegmentcombined_textline	last_linehas_newlinenewline_segmentlast_segmentlast_line_text	separatorr4   wrapped_segmentss                     r   __rich_console__zInlineText.__rich_console__>   si    ("&&tzz +-b<~~d&=&=wG 	-G||t#!((	)AB!##G,	- $$\2 !zz -tzz :">>-AAA &cr* 	D 	 )"-I $B	"(:(:d(BK1<immo$O (}& %%,,.&,,(00 
 !-	" """-N$ G<<"))',,FG S	I

 '!"i/N$&'  $GNN>7$KL##/3(9(9(B(B4(H$++GDM:  ''8'''S  Bf (s,   CIIB*I CIIII)r   r   )r4   r	   )__name__
__module____qualname__r   classmethodstrboolr   r1   r3   rP    r   r   r   r      sm    PU /
  !&!"Ht"H "H
 "H "H 
"H "HH J(r   r   )__doc__systypingr   version_infor   typing_extensionsrich.consoler   r(   r	   r   rW   r   r   <module>r^      s7    F 
  w&+x( x(r   