feat: рабочая версия дебаггера
скорее всего конкретно в TUI ничего уже меняться не будет
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
from dpdebugger import Debugger
|
from dpdebugger import Debugger
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import cast
|
||||||
import math
|
import math
|
||||||
import py_cui
|
import py_cui
|
||||||
import py_cui.keys
|
import py_cui.keys
|
||||||
import re
|
from collections import deque
|
||||||
import shlex
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SourceLines:
|
class SourceLines:
|
||||||
@ -57,6 +57,9 @@ class DebuggerUI:
|
|||||||
row_span=1
|
row_span=1
|
||||||
)
|
)
|
||||||
self.prompt_panel.add_key_command(py_cui.keys.KEY_ENTER, self._process_prompt)
|
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",
|
self.terminal_panel = self.master.add_text_block("Debugger Console",
|
||||||
2, 0,
|
2, 0,
|
||||||
initial_text="to exit type in \"exit\""
|
initial_text="to exit type in \"exit\""
|
||||||
@ -66,16 +69,27 @@ class DebuggerUI:
|
|||||||
py_cui.keys.KEY_ENTER,
|
py_cui.keys.KEY_ENTER,
|
||||||
lambda: self.master.move_focus(self.prompt_panel)
|
lambda: self.master.move_focus(self.prompt_panel)
|
||||||
)
|
)
|
||||||
|
self.commands_history: deque[str] = deque(maxlen=10)
|
||||||
self._display_source_lines()
|
self._display_source_lines()
|
||||||
|
|
||||||
def _process_prompt(self):
|
def _process_prompt(self):
|
||||||
user_input = self.prompt_panel.get()
|
user_input = self.prompt_panel.get()
|
||||||
|
self.prompt_panel.clear()
|
||||||
if user_input == "exit":
|
if user_input == "exit":
|
||||||
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())
|
dbg_output = self.dbg.do_command(user_input.split())
|
||||||
self.terminal_panel.write(dbg_output)
|
self.terminal_panel.write(dbg_output)
|
||||||
self._display_source_lines()
|
self._display_source_lines()
|
||||||
|
self.commands_history[0] = user_input
|
||||||
|
|
||||||
def _display_source_lines(self):
|
def _display_source_lines(self):
|
||||||
active_line = self.dbg.get_current_source_line_number()
|
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))
|
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):
|
def main(debugger: Debugger, srcfile: str):
|
||||||
root = py_cui.PyCUI(3, 1)
|
root = py_cui.PyCUI(3, 1)
|
||||||
root.set_title("Stupid DP32 debugger")
|
root.set_title("Stupid DP32 debugger")
|
||||||
|
|||||||
Reference in New Issue
Block a user