From 82eb4e96ff88e29e145f0b0cbc38c546ba522b47 Mon Sep 17 00:00:00 2001 From: ElectronixTM Date: Wed, 2 Apr 2025 00:39:24 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dbg_tui.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/dbg_tui.py b/src/dbg_tui.py index 7239363..b3ecd4e 100644 --- a/src/dbg_tui.py +++ b/src/dbg_tui.py @@ -1,4 +1,5 @@ from dpdebugger import Debugger +from vm import VMException, VMExceptionType, VMStatus from dataclasses import dataclass from typing import cast import math @@ -86,13 +87,41 @@ class DebuggerUI: 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) + + try: + dbg_output = self.dbg.do_command(user_input.split()) + except VMException as vme: + self._terminal_append( + "VM Exception: " + vme.message + ) + return + + # self._terminal_append(dbg_output) + self._terminal_append(dbg_output) self._display_source_lines() self.commands_history[0] = user_input + def _terminal_append(self, text: str): + self.terminal_panel.write(text) + viewport_height = self.terminal_panel.get_viewport_height() + contents = self.terminal_panel.get().split('\n')[-viewport_height:] + self.terminal_panel.set_text("\n".join(contents)) + def _display_source_lines(self): - active_line = self.dbg.get_current_source_line_number() + if self.dbg._vm.status == VMStatus.FINISHED: + return + try: + active_line = self.dbg.get_current_source_line_number() + except KeyError: + self._terminal_append( + "Cant find source line your are on. " + "May be you reached end of program. " + ) + self._terminal_append( + "Please type \"reset\" to reset vm " + "it's initial state" + ) + return lines = _get_source_lines( srcline=active_line, lines=self.srclines,