A class for displaying a list of stored stacktraces in the TUI.
This class provides a view for browsing and selecting stacktraces
from the current session.
The constructor for the StacktraceListInterface class.
Parameters:
-
terminal
(Terminal)
–
The blessed Terminal instance.
Source code in dev_tool/tui/stacktrace/collection.py
| def __init__(self, terminal: Terminal) -> None:
"""
The constructor for the StacktraceListInterface class.
:param terminal: The blessed Terminal instance.
"""
self._header_style: str = ''
self._selected_style: str = ''
self._status_style: str = ''
self.offset = 0
self.selected_index = 0
self.service = StacktraceService()
self.terminal = terminal
|
A method that draws the stacktrace list view.
Source code in dev_tool/tui/stacktrace/collection.py
| def draw_list(self) -> None:
"""A method that draws the stacktrace list view."""
width = self.terminal.width
output = []
output.append(self.terminal.home + self.terminal.clear)
self._build_styles()
entries = self.service.get_all()
count = len(entries)
header = f' Stacktraces ({count})'
header = self._pad_line(header, width)
output.append(
move(self.terminal, 0, 0) +
self._header_style +
header +
self.terminal.normal
)
start_line = 2
available_lines = self.terminal.height - start_line - 2
if not entries:
empty_message = ' No stacktraces stored in this session.'
output.append(move(self.terminal, start_line, 0) + empty_message)
else:
maximum = max(0, count - available_lines)
self.offset = min(self.offset, maximum)
self.offset = max(0, self.offset)
self.selected_index = min(self.selected_index, count - 1)
self.selected_index = max(0, self.selected_index)
if self.selected_index < self.offset:
self.offset = self.selected_index
elif self.selected_index >= self.offset + available_lines:
self.offset = self.selected_index - available_lines + 1
end_index = min(count, self.offset + available_lines)
for i in range(available_lines):
entry_index = self.offset + i
line_number = start_line + i
if entry_index < end_index:
entry = entries[entry_index]
line = self._format_entry(entry, entry_index, width - 4)
line = self._pad_line(line, width)
if entry_index == self.selected_index:
output.append(
move(self.terminal, line_number, 0) +
self._selected_style +
line +
self.terminal.normal
)
else:
output.append(move(self.terminal, line_number, 0) + line)
else:
output.append(move(self.terminal, line_number, 0) + ' ' * width)
status_text = ' Enter to view | x to clear all | s or Backspace to close '
status_text = self._pad_line(status_text, width)
status_line = self.terminal.height - 1
output.append(
move(self.terminal, status_line, 0) +
self._status_style +
status_text +
self.terminal.normal
)
print(''.join(output), end='', flush=True) # noqa: T201
|
get_selected_entry
A method that gets the currently selected stacktrace entry.
Returns:
Source code in dev_tool/tui/stacktrace/collection.py
| def get_selected_entry(self) -> StacktraceEntry | None:
"""
A method that gets the currently selected stacktrace entry.
:return: The selected entry, or None if no entries exist.
"""
return self.service.get(self.selected_index)
|
A method that handles input for the stacktrace list interface.
Parameters:
Returns:
-
str | None
–
The navigation result or None to continue.
Source code in dev_tool/tui/stacktrace/collection.py
| def handle_input(self, key: str) -> str | None:
"""
A method that handles input for the stacktrace list interface.
:param key: The key name.
:return: The navigation result or None to continue.
"""
match key:
case Key.UP:
self.selected_index = max(0, self.selected_index - 1)
return MenuAction.REDRAW
case Key.DOWN:
count = self.service.get_count()
self.selected_index = min(count - 1, self.selected_index + 1)
return MenuAction.REDRAW
case _ if key in (Key.ENTER, Key.LINE_FEED, Key.CARRIAGE_RETURN):
if self.service.get_count() > 0:
return MenuAction.SELECTED
return None
case _ if key.lower() == Key.DISMISS:
self.service.clear()
self.selected_index = 0
self.offset = 0
return MenuAction.REDRAW
case _ if key in (Key.BACKSPACE, Key.DELETE, Key.ESCAPE) or key.lower() == Key.STACKTRACE_COLLECTION:
return MenuAction.MAIN_MENU
case _ if key.lower() == Key.QUIT:
return MenuAction.QUIT
case _:
return None
|
A method that resets the selection state.
Source code in dev_tool/tui/stacktrace/collection.py
| def reset(self) -> None:
"""A method that resets the selection state."""
self.offset = 0
self.selected_index = 0
|