
    BVh                     R    d Z ddlZddlmZ ddlmZ  G d dej
                        Zy)zEReadline-Based Command-Line Interface of TensorFlow Debugger (tfdbg).    N)base_ui)debugger_cli_commonc                   L    e Zd ZdZddZd Zd Z	 	 	 	 ddZd Zd Z	d	 Z
d
 Zy)
ReadlineUIzReadline-based Command-line UI.Nc                 h    t         j                  j                  | ||       | j                          y )N)
on_ui_exitconfig)r   BaseUI__init___init_input)selfr   r	   s      W/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/debug/cli/readline_ui.pyr   zReadlineUI.__init__   s'    NNDZG    c                     t        j                  d       t        j                  d       t        j                  | j                         t        j                  d       t
        | _        y )Nzset editing-mode emacs
ztab: complete)readlineparse_and_bindset_completer_delimsset_completer_readline_completeinput_inputr   s    r   r   zReadlineUI._init_input   sJ    45 !!$'4223O,DKr   c                     | j                  |      \  }}}| j                  j                  ||      \  }}|D cg c]  }||z   	 }}||   S c c}w N)_analyze_tab_complete_input_tab_completion_registryget_completions)	r   textstatecontextprefixexcept_last_word
candidates_	candidates	            r   r   zReadlineUI._readline_complete(   sd    (,(H(H(N%GV%11AA'BHJMJBLMY#i/MJMe Ns   Ac                     t        |       || j                  |       | j                         }| j                  r| j                          |S )zCRun the CLI: See the doc of base_ui.BaseUI.run_ui for more details.)print_dispatch_command_ui_loop_on_ui_exit)r   init_commandtitletitle_colorenable_mouse_on_start
exit_tokens         r   run_uizReadlineUI.run_ui/   sE     
%L
\*J
r   c                 P    	 | j                         }| j                  |      }||S &r   )_get_user_commandr)   )r   commandr0   s      r   r*   zReadlineUI._ui_loopB   s4    
&&(g))'2j		 r   c                 j    t        d       | j                  | j                        j                         S )N )r(   r   
CLI_PROMPTstripr   s    r   r3   zReadlineUI._get_user_commandJ   s%    	"I;;t'--//r   c                 |   || j                   v rt        j                  S 	 | j                  |      \  }}}| j                  j                  |      r 	 | j                  j                  ||d      }n&t        j                  | j                  d|z  z   g      }| j                  |       |r!	 |j                  |       t        d|z         yy# t        $ r}t        t        |             Y d}~yd}~ww xY w# t        j                  $ r}|j                  cY d}~S d}~ww xY w# t         $ r t        d|z         Y yw xY w)zDispatch user command.

    Args:
      command: (str) Command to dispatch.

    Returns:
      An exit token object. None value means that the UI loop should not exit.
      A non-None value means the UI loop should exit.
    N)screen_infozInvalid command prefix "%s"zWrote output to %szFailed to write output to %s)CLI_EXIT_COMMANDSr   EXPLICIT_USER_EXIT_parse_commandSyntaxErrorr(   str_command_handler_registryis_registereddispatch_commandCommandLineExitr0   RichTextLinesERROR_MESSAGE_PREFIX_display_outputwrite_to_file	Exception)r   r4   r"   argsoutput_file_pathescreen_outputs          r   r)   zReadlineUI._dispatch_commandN   sD    $((( !333'+':':7'C$fd$
 %%33F;66GGDd H ,
 *77

#
#&E&N
N9 	m 	'A##$45"%556 !  CFm !00 ||  A,/??@AsG   C C5 *D! 	C2C--C25DDDD!D;:D;c                 <    |j                   D ]  }t        |        y r   )linesr(   )r   rL   lines      r   rF   zReadlineUI._display_outputw   s    ## Dkr   )NN)NNNT)__name__
__module____qualname____doc__r   r   r   r1   r*   r3   r)   rF    r   r   r   r      s=    '	 #'	&0'ARr   r   )rS   r   tensorflow.python.debug.clir   r   r
   r   rT   r   r   <module>rV      s&    L  / ;c cr   