
    BVh                     J    d Z ddlZddlmZ ddlmZ ddlmZ  G d de      Zy)zABase Class of TensorFlow Debugger (tfdbg) Command-Line Interface.    N)
cli_config)command_parser)debugger_cli_commonc                   v    e Zd ZdZdZddgZdZdZddZd	 Z		 dd
Z
d Z	 	 	 	 ddZd Zd Zed        ZddZy)BaseUIz#Base class of tfdbg user interface.ztfdbg> exitquitzERROR: zINFO: Nc                    || _         t        j                         | _        t        j                         | _        | j
                  j                  dg| j                  t        j                  j                  gz   t        j                  j                  z          |xs t        j                         | _        t        j                  dt        j                        | _        | j                   j#                         }|j%                  d      }|j'                  dt(               |j'                  dt(               |j%                  d      }| j+                  d	| j,                  | j                   j/                         d
g       y)zConstructor of the base class.

    Args:
      on_ui_exit: (`Callable`) the callback to be called when the UI exits.
      config: An instance of `cli_config.CLIConfig()` carrying user-facing
        configurations.
     zconfig command)descriptionusagesetproperty_name)typeproperty_valueshowconfigcfgprefix_aliasesN)_on_ui_exitr   CommandHandlerRegistry_command_handler_registryTabCompletionRegistry_tab_completion_registryregister_tab_comp_contextCLI_EXIT_COMMANDSHELP_COMMANDHELP_COMMAND_ALIASESr   	CLIConfig_configargparseArgumentParserSUPPRESS_config_argparseradd_subparsers
add_parseradd_argumentstrregister_command_handler_config_command_handlerformat_help)self
on_ui_exitr   
subparsers
set_parsers        S/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/debug/cli/base_ui.py__init__zBaseUI.__init__   sL    "D 	224 	" %8$M$M$OD! 	!!;;	d$$		3	3	@	@AB22GGHI
 3Z113DL%44$H,=,=?D''668J&&u-JO#6,37&&v.J!!$$**,w	 "      c                 <    | j                   j                  |       y)zSet an introductory message to the help output of the command registry.

    Args:
      help_intro: (RichTextLines) Rich text lines appended to the beginning of
        the output of the command "help", as introductory information.
    )
help_introN)r   set_help_intro)r-   r5   s     r1   r6   zBaseUI.set_help_introD   s     	""11Z1Hr3   c                     | j                   j                  ||||       | j                  j                  d|g       |r| j                  j                  d|       yy)a  A wrapper around CommandHandlerRegistry.register_command_handler().

    In addition to calling the wrapped register_command_handler() method, this
    method also registers the top-level tab-completion context based on the
    command prefixes and their aliases.

    See the doc string of the wrapped method for more details on the args.

    Args:
      prefix: (str) command prefix.
      handler: (callable) command handler.
      help_info: (str) help information.
      prefix_aliases: (list of str) aliases of the command prefix.
    r   r   N)r   r*   r   extend_comp_items)r-   prefixhandler	help_infor   s        r1   r*   zBaseUI.register_command_handlerN   s_    ( 	"";;> < C 	!!33BA
##55b.I r3   c                 <     | j                   j                  |i | y)zAWrapper around TabCompletionRegistry.register_tab_comp_context().N)r   r   )r-   argskwargss      r1   r   z BaseUI.register_tab_comp_contexti   s     <D!!;;TLVLr3   c                     t        d      )a  Run the UI until user- or command- triggered exit.

    Args:
      init_command: (str) Optional command to run on CLI start up.
      title: (str) Optional title to display in the CLI.
      title_color: (str) Optional color of the title, e.g., "yellow".
      enable_mouse_on_start: (bool) Whether the mouse mode is to be enabled on
        start-up.

    Returns:
      An exit token of arbitrary type. Can be None.
    z%run_ui() is not implemented in BaseUI)NotImplementedError)r-   init_commandtitletitle_colorenable_mouse_on_starts        r1   run_uizBaseUI.run_uin   s    $ E
FFr3   c                     |j                         }|sdg dfS t        j                  |      }t        j                  |      \  }}|d   |dd |fS )aa  Parse a command string into prefix and arguments.

    Args:
      command: (str) Command string to be parsed.

    Returns:
      prefix: (str) The command prefix.
      args: (list of str) The command arguments (i.e., not including the
        prefix).
      output_file_path: (str or None) The path to save the screen output
        to (if any).
    r   Nr      )stripr   parse_commandextract_output_file_path)r-   commandcommand_itemsoutput_file_paths       r1   _parse_commandzBaseUI._parse_command   sc     mmoGT\"009M&4&M&M'#M# ]12.0@@@r3   c                     |j                         }|sd}d}d}nJ|j                  d      }t        |      dk(  r
d}|d   }d}n!|d   }|d   }dj                  |dd       dz   }|||fS )aM  Analyze raw input to tab-completer.

    Args:
      text: (str) the full, raw input text to be tab-completed.

    Returns:
      context: (str) the context str. For example,
        If text == "print_tensor softmax", returns "print_tensor".
        If text == "print", returns "".
        If text == "", returns "".
      prefix: (str) the prefix to be tab-completed, from the last word.
        For example, if text == "print_tensor softmax", returns "softmax".
        If text == "print", returns "print".
        If text == "", returns "".
      except_last_word: (str) the input text, except the last word.
        For example, if text == "print_tensor softmax", returns "print_tensor".
        If text == "print_tensor -a softmax", returns "print_tensor -a".
        If text == "print", returns "".
        If text == "", returns "".
    r    rG   r   N)lstripsplitlenjoin)r-   textcontextr9   except_last_worditemss         r1   _analyze_tab_complete_inputz"BaseUI._analyze_tab_complete_input   s    * ;;=Dgfjjoe	Uqq (r88E#2J/#5F,,,r3   c                     | j                   S )z/Obtain the CLIConfig of this `BaseUI` instance.)r!   )r-   s    r1   r   zBaseUI.config   s     <<r3   c                 J   ~| j                   j                  |      }t        |d      rbt        |d      rV| j                  j	                  |j
                  |j                         | j                  j                  |j
                        S | j                  j                         S )z)Command handler for the "config" command.r   r   )	highlight)r%   
parse_argshasattrr!   r   r   r   	summarize)r-   r=   screen_infoparseds       r1   r+   zBaseUI._config_command_handler   s    ##..t4Fv'GF<L,M
llv++V-B-BC\\##f.B.B#CC \\##%%r3   )NN)N)NNNT)__name__
__module____qualname____doc__
CLI_PROMPTr   ERROR_MESSAGE_PREFIXINFO_MESSAGE_PREFIXr2   r6   r*   r   rE   rN   rZ   propertyr   r+    r3   r1   r   r      sw    +*v&" # JI /3	J6M #'	G(A.(-T  &r3   r   )rf   r"   tensorflow.python.debug.clir   r   r   objectr   rk   r3   r1   <module>rn      s%    H  2 6 ;|&V |&r3   