
                              d Z ddlmZ ddlmZ ddlmZ ddl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ej                         Zd Zd Zd Zd Zy)z&Code for the gcloud shell help window.    )absolute_import)division)unicode_literalsN)cli_tree_markdown)parser)render_document)token_renderer)controlsc                       e Zd ZdZddZd Zy)HelpWindowControlz"Implementation of the help window.Nc                     || _         y N)_default_char)selfdefault_chars     9lib/googlecloudsdk/command_lib/interactive/help_window.py__init__zHelpWindowControl.__init__"   s
    %D    c                 z    t        ||      t        j                  fdt              d| j                        S )Nc                     |    S r    )idatas    r   <lambda>z2HelpWindowControl.create_content.<locals>.<lambda>)   s	    $q'r   F)
line_countshow_cursorr   )GenerateHelpContentr
   	UIContentlenr   )r   cliwidthheightr   s       @r   create_contentz HelpWindowControl.create_content%   s8    sE*Dt9''	) )r   r   )__name__
__module____qualname____doc__r   r#   r   r   r   r   r      s    *&)r   r   c                 t   |dkD  rd}| j                   j                  }| j                  j                  |j                        }|sg S |d   }|j
                  t        j                  j                  t        j                  j                  fv rt        | ||      S |j
                  t        j                  j                  k(  rt        | ||      S |j
                  t        j                  j                  k(  rt        | |d   |      S |j
                  t        j                  j                  k(  rt        | ||      S g S )z)Returns help lines for the current token.P   )current_bufferdocumentr   ParseCommandtext_before_cursor
token_typeArgTokenTypeGROUPCOMMANDGenerateHelpForCommandFLAGGenerateHelpForFlagFLAG_ARG
POSITIONALGenerateHelpForPositional)r    r!   docargsargs        r   r   r   /   s    
RZE###		 	 !7!7	8$	IR#^^++1163F3F3N3NOO!#sE22
~~,,111sC//
~~,,555sDHe44
~~,,777$S#u55	)r   c           	         g }d}t        j                  |j                  | j                        }|j	                  dd       |j                         }t        j                  |      }|j                  t        j                  t        j                  ||      |      j                                |j                  g        d}t        j                  |j                  | j                        }|j                          |j                         }t        j                  |      }|j                  t        j                  t        j                  ||d	      |      j                                |S )
z'Returns help lines for a command token.   DESCRIPTIONT)disable_headerr!   r"   fin   F)r!   r"   compact)markdownCliTreeMarkdownGeneratortreerootPrintSectionIfExistsEditioStringIOextendr   MarkdownRendererr	   TokenRendererRunappendPrintSynopsisSection)r    tokenr!   linesr"   genr:   rC   s           r   r4   r4   E   s   
% &))%**chh?#=>
#
C#,,//""f&+.0037 ,,r &))%**chh?#
#
C#,,//""fe5:=??BsuF 
,r   c                 r   t        j                  | j                  | j                        }|j                  |j                         |j                         }t        j                  |      }t        j                  t        j                  || j                  j                        |      j                         S )z$Returns help lines for a flag token.rA   rB   )rF   rG   rI   PrintFlagDefinitionrH   rK   rL   rM   r   rO   r	   rP   config
help_linesrQ   r    rT   r!   rV   markrC   s         r   r6   r6   b   s    ))#((CHH=#%**%	$
D#		)	)""cjj335:=
??BsuEr   c                    t        j                  | j                  | j                        }|j                  t        j                  |j
                               |j                         }t        j                  |      }t        j                  t        j                  || j                  j                        |      j                         S )z*Returns help lines for a positional token.rA   rB   )rF   rG   rI   PrintPositionalDefinition
PositionalrH   rK   rL   rM   r   rO   r	   rP   rY   rZ   rQ   r[   s         r   r9   r9   n   s    ))#((CHH=# 3 3EJJ ?@	$
D#		)	)""cjj335:=
??BsuEr   )r'   
__future__r   r   r   rL   googlecloudsdk.callioper   rF   &googlecloudsdk.command_lib.interactiver   &googlecloudsdk.core.document_renderersr   r	   prompt_toolkit.layoutr
   	UIControlr   r   r4   r6   r9   r   r   r   <module>rf      sM     - &  ' 	 A 9 B A *)** ) ,:	E	Er   