def testCommandHistoryHandlesWritingIOErrorGracoiusly(self): with open(self._history_file_path, "wt") as f: f.write("help\n") # Change file to read-only. os.chmod(self._history_file_path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) # Reading from the file should still work. cmd_hist_2 = debugger_cli_common.CommandHistory( limit=3, history_file_path=self._history_file_path) self.assertEqual(["help"], cmd_hist_2.most_recent_n(1)) # Writing should no longer work, but it should fail silently and # the within instance-command history should still work. cmd_hist_2.add_command("foo") self.assertEqual(["help", "foo"], cmd_hist_2.most_recent_n(2)) cmd_hist_3 = debugger_cli_common.CommandHistory( limit=3, history_file_path=self._history_file_path) self.assertEqual(["help"], cmd_hist_3.most_recent_n(1)) # Change the file to back to read-write. os.chmod(self._history_file_path, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH))
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()) 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._curr_unwrapped_output = None self._curr_wrapped_output = None
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 testCommandHistoryHandlesReadingIOErrorGracoiusly(self): with open(self._history_file_path, "wt") as f: f.write("help\n") # Change file to not readable by anyone. os.chmod(self._history_file_path, 0) # The creation of a CommandHistory object should not error out. debugger_cli_common.CommandHistory(limit=3)
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)
def testLoadingCommandHistoryFileObeysLimit(self): self._cmd_hist.add_command("help 1") self._cmd_hist.add_command("help 2") self._cmd_hist.add_command("help 3") self._cmd_hist.add_command("help 4") cmd_hist_2 = debugger_cli_common.CommandHistory(limit=3) self.assertEqual(["help 2", "help 3", "help 4"], cmd_hist_2.most_recent_n(3)) with open(self._history_file_path, "rt") as f: self.assertEqual( ["help 2\n", "help 3\n", "help 4\n"], f.readlines())
def __init__(self, on_ui_exit=None): """Constructor of CursesUI. Args: on_ui_exit: (Callable) Callback invoked when the UI exits. """ base_ui.BaseUI.__init__(self, on_ui_exit=on_ui_exit) 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_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) self.register_command_handler( "mouse", self._mouse_mode_command_handler, "Get or set the mouse mode of this CLI: (on|off)", prefix_aliases=["m"])
def setUp(self): self._cmd_hist = debugger_cli_common.CommandHistory(limit=3) self._history_file_path = os.path.join( os.path.expanduser("~"), debugger_cli_common.CommandHistory._HISTORY_FILE_NAME)
def setUp(self): self._cmd_hist = debugger_cli_common.CommandHistory(limit=3)
def setUp(self): self._fd, self._history_file_path = tempfile.mkstemp() self._cmd_hist = debugger_cli_common.CommandHistory( limit=3, history_file_path=self._history_file_path)