B
    һd                 @   s:   d Z ddlZddlmZ ddlmZ G dd dejZdS )zEReadline-Based Command-Line Interface of TensorFlow Debugger (tfdbg).    N)base_ui)debugger_cli_commonc               @   sT   e Zd ZdZdddZdd Zdd Zdd
dZdd Zdd Z	dd Z
dd ZdS )
ReadlineUIzReadline-based Command-line UI.Nc             C   s   t jj| ||d |   d S )N)
on_ui_exitconfig)r   BaseUI__init___init_input)selfr   r    r   Y/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/debug/cli/readline_ui.pyr      s    zReadlineUI.__init__c             C   s4   t d t d t | j t d t| _d S )Nzset editing-mode emacs
ztab: complete)readlineparse_and_bindZset_completer_delimsZset_completer_readline_completeinput_input)r
   r   r   r   r	      s
    


zReadlineUI._init_inputc                s<   |  |\}} | j||\}} fdd|D }|| S )Nc                s   g | ]} | qS r   r   ).0	candidate)except_last_wordr   r   
<listcomp>,   s    z1ReadlineUI._readline_complete.<locals>.<listcomp>)Z_analyze_tab_complete_inputZ_tab_completion_registryZget_completions)r
   textstatecontextprefix
candidates_r   )r   r   r   (   s
    
zReadlineUI._readline_completeTc             C   s4   t | |dk	r| | |  }| jr0|   |S )zCRun the CLI: See the doc of base_ui.BaseUI.run_ui for more details.N)print_dispatch_command_ui_loopZ_on_ui_exit)r
   Zinit_commandtitletitle_colorZenable_mouse_on_start
exit_tokenr   r   r   run_ui/   s    
zReadlineUI.run_uic             C   s(   x"|   }| |}|d k	r|S qW d S )N)_get_user_commandr   )r
   commandr"   r   r   r   r   B   s
    
zReadlineUI._ui_loopc             C   s   t d | | j S )N )r   r   Z
CLI_PROMPTstrip)r
   r   r   r   r$   J   s    zReadlineUI._get_user_commandc          
   C   s  || j krtjS y| |\}}}W n. tk
rR } ztt| dS d}~X Y nX | j|ry| jj	||dd}W q tj
k
r } z|jS d}~X Y qX nt| jd|  g}| | |ry|| td|  W n" tk
r   td|  Y nX dS )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)Zscreen_infozInvalid command prefix "%s"zWrote output to %szFailed to write output to %s)ZCLI_EXIT_COMMANDSr   ZEXPLICIT_USER_EXITZ_parse_commandSyntaxErrorr   strZ_command_handler_registryZis_registeredZdispatch_commandZCommandLineExitr"   ZRichTextLinesZERROR_MESSAGE_PREFIX_display_outputZwrite_to_file	Exception)r
   r%   r   argsZoutput_file_pathescreen_outputr   r   r   r   N   s,    


zReadlineUI._dispatch_commandc             C   s   x|j D ]}t| qW d S )N)linesr   )r
   r.   liner   r   r   r*   w   s    zReadlineUI._display_output)NN)NNNT)__name__
__module____qualname____doc__r   r	   r   r#   r   r$   r   r*   r   r   r   r   r      s   
   
)r   )r4   r   Ztensorflow.python.debug.clir   r   r   r   r   r   r   r   <module>   s   