feat: исправлено поведение консоли при переполнении сделана обработка исключений

This commit is contained in:
ElectronixTM
2025-04-02 00:39:24 +03:00
parent eae2846925
commit 82eb4e96ff

View File

@ -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,