Пример #1
0
    def __init__(self, on_ui_exit=None):
        """Constructor of CursesUI.

    Args:
      on_ui_exit: (Callable) Callback invoked when the UI exits.
    """

        self._screen_init()
        self._screen_refresh_size()
        # TODO(cais): Error out if the size of the screen is too small.

        # Initialize some UI component size and locations.
        self._init_layout()

        self._command_handler_registry = (
            debugger_cli_common.CommandHandlerRegistry())

        # Create tab completion registry and register the empty-str (top-level)
        # tab-completion context with it.
        self._tab_completion_registry = debugger_cli_common.TabCompletionRegistry(
        )

        # Create top-level tab-completion context and register the exit and help
        # commands.
        self._tab_completion_registry.register_tab_comp_context(
            [""], self.CLI_EXIT_COMMANDS +
            [debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND] +
            debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND_ALIASES)

        self._command_history_store = debugger_cli_common.CommandHistory()

        # Active list of command history, used in history navigation.
        # _command_handler_registry holds all the history commands the CLI has
        # received, up to a size limit. _active_command_history is the history
        # currently being navigated in, e.g., using the Up/Down keys. The latter
        # can be different from the former during prefixed or regex-based history
        # navigation, e.g., when user enter the beginning of a command and hit Up.
        self._active_command_history = []

        # Pointer to the current position in the history sequence.
        # 0 means it is a new command being keyed in.
        self._command_pointer = 0

        self._command_history_limit = 100

        self._pending_command = ""

        # State related to screen output.
        self._output_pad = None
        self._output_pad_row = 0
        self._output_array_pointer_indices = None
        self._curr_unwrapped_output = None
        self._curr_wrapped_output = None

        # Register signal handler for SIGINT.
        signal.signal(signal.SIGINT, self._interrupt_handler)

        # Configurable callbacks.
        self._on_ui_exit = on_ui_exit
  def setUp(self):
    self._tc_reg = debugger_cli_common.TabCompletionRegistry()

    # Register the items in an unsorted order deliberately, to test the sorted
    # output from get_completions().
    self._tc_reg.register_tab_comp_context(
        ["print_tensor", "pt"],
        ["node_b:1", "node_b:2", "node_a:1", "node_a:2"])
    self._tc_reg.register_tab_comp_context(["node_info"],
                                           ["node_c", "node_b", "node_a"])
Пример #3
0
    def __init__(self):
        self._screen_init()
        self._screen_refresh_size()
        # TODO(cais): Error out if the size of the screen is too small.

        # Initialize some UI component size and locations.
        self._init_layout()

        self._command_handler_registry = (
            debugger_cli_common.CommandHandlerRegistry())

        # Create tab completion registry and register the empty-str (top-level)
        # tab-completion context with it.
        self._tab_completion_registry = debugger_cli_common.TabCompletionRegistry(
        )

        # Create top-level tab-completion context and register the exit and help
        # commands.
        self._tab_completion_registry.register_tab_comp_context(
            [""], self.CLI_EXIT_COMMANDS +
            [debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND] +
            debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND_ALIASES)

        self._command_history_store = debugger_cli_common.CommandHistory()

        # Active list of command history, used in history navigation.
        # _command_handler_registry holds all the history commands the CLI has
        # received, up to a size limit. _active_command_history is the history
        # currently being navigated in, e.g., using the Up/Down keys. The latter
        # can be different from the former during prefixed or regex-based history
        # navigation, e.g., when user enter the beginning of a command and hit Up.
        self._active_command_history = []

        # Pointer to the current position in the history sequence.
        # 0 means it is a new command being keyed in.
        self._command_pointer = 0

        self._command_history_limit = 100

        self._pending_command = ""

        # State related to screen output.
        self._output_pad = None
        self._curr_unwrapped_output = None
        self._curr_wrapped_output = None

        # NamedTuple for rectangular locations on screen
        self.rectangle = collections.namedtuple("rectangle",
                                                "top left bottom right")

        # Register signal handler for SIGINT.
        signal.signal(signal.SIGINT, self._interrupt_handler)
Пример #4
0
    def __init__(self, on_ui_exit=None):
        """Constructor of the base class.

    Args:
      on_ui_exit: (`Callable`) the callback to be called when the UI exits.
    """

        self._on_ui_exit = on_ui_exit

        self._command_handler_registry = (
            debugger_cli_common.CommandHandlerRegistry())

        self._tab_completion_registry = debugger_cli_common.TabCompletionRegistry(
        )

        # Create top-level tab-completion context and register the exit and help
        # commands.
        self._tab_completion_registry.register_tab_comp_context(
            [""], self.CLI_EXIT_COMMANDS +
            [debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND] +
            debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND_ALIASES)
Пример #5
0
    def __init__(self, on_ui_exit=None, config=None):
        """Constructor 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.
    """

        self._on_ui_exit = on_ui_exit

        self._command_handler_registry = (
            debugger_cli_common.CommandHandlerRegistry())

        self._tab_completion_registry = debugger_cli_common.TabCompletionRegistry(
        )

        # Create top-level tab-completion context and register the exit and help
        # commands.
        self._tab_completion_registry.register_tab_comp_context(
            [""], self.CLI_EXIT_COMMANDS +
            [debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND] +
            debugger_cli_common.CommandHandlerRegistry.HELP_COMMAND_ALIASES)

        self._config = config or cli_config.CLIConfig()
        self._config_argparser = argparse.ArgumentParser(
            description="config command", usage=argparse.SUPPRESS)
        subparsers = self._config_argparser.add_subparsers()
        set_parser = subparsers.add_parser("set")
        set_parser.add_argument("property_name", type=str)
        set_parser.add_argument("property_value", type=str)
        set_parser = subparsers.add_parser("show")
        self.register_command_handler("config",
                                      self._config_command_handler,
                                      self._config_argparser.format_help(),
                                      prefix_aliases=["cfg"])