From 922670be473e2a71191f07cd3ea61b687af4022d Mon Sep 17 00:00:00 2001 From: ElectronixTM Date: Tue, 1 Apr 2025 16:50:31 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=B3=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit скорее всего конкретно в TUI ничего уже меняться не будет --- src/dbg_tui.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/dbg_tui.py b/src/dbg_tui.py index d81190d..7239363 100644 --- a/src/dbg_tui.py +++ b/src/dbg_tui.py @@ -1,10 +1,10 @@ from dpdebugger import Debugger from dataclasses import dataclass +from typing import cast import math import py_cui import py_cui.keys -import re -import shlex +from collections import deque @dataclass class SourceLines: @@ -57,6 +57,9 @@ class DebuggerUI: row_span=1 ) self.prompt_panel.add_key_command(py_cui.keys.KEY_ENTER, self._process_prompt) + self.history_index = 0 + self.prompt_panel.add_key_command(py_cui.keys.KEY_UP_ARROW, self._history_up) + self.prompt_panel.add_key_command(py_cui.keys.KEY_DOWN_ARROW, self._history_down) self.terminal_panel = self.master.add_text_block("Debugger Console", 2, 0, initial_text="to exit type in \"exit\"" @@ -66,16 +69,27 @@ class DebuggerUI: py_cui.keys.KEY_ENTER, lambda: self.master.move_focus(self.prompt_panel) ) + self.commands_history: deque[str] = deque(maxlen=10) self._display_source_lines() def _process_prompt(self): user_input = self.prompt_panel.get() + self.prompt_panel.clear() if user_input == "exit": exit() - self.prompt_panel.clear() + if user_input == "clear": + self.terminal_panel.clear() + return + if user_input.strip() == "": + if len(self.commands_history) < 1: + return + user_input = self.commands_history[0] + self.history_index = 0 + self.commands_history.appendleft("") dbg_output = self.dbg.do_command(user_input.split()) self.terminal_panel.write(dbg_output) self._display_source_lines() + self.commands_history[0] = user_input def _display_source_lines(self): active_line = self.dbg.get_current_source_line_number() @@ -99,6 +113,20 @@ class DebuggerUI: ) self.source_panel.set_text("\n".join(lines_with_linenos)) + def _history_up(self): + if len(self.commands_history) == 0: + return + self.history_index += 1 + self.history_index %= len(self.commands_history) + self.prompt_panel.set_text(self.commands_history[self.history_index]) + + def _history_down(self): + if len(self.commands_history) == 0: + return + self.history_index -= 1 + self.history_index %= len(self.commands_history) + self.prompt_panel.set_text(self.commands_history[self.history_index]) + def main(debugger: Debugger, srcfile: str): root = py_cui.PyCUI(3, 1) root.set_title("Stupid DP32 debugger")