cleanup what I just did
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QTextEdit, QLineEdit
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
from src.shared.shareddata import APP_NAME, CURRENT_VERSION
|
||||
|
||||
|
||||
class TerminalWindow(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, Qt.WindowType.Window)
|
||||
self.setWindowTitle(f"Terminal - {APP_NAME.upper()}")
|
||||
|
||||
self.output_area = QTextEdit()
|
||||
self.output_area.setReadOnly(True)
|
||||
|
||||
self.input_line = QLineEdit()
|
||||
self.input_line.returnPressed.connect(self.handle_command)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.output_area)
|
||||
layout.addWidget(self.input_line)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.commands = {
|
||||
"hello": self.cmd_hello,
|
||||
"help": self.cmd_help,
|
||||
"version": self.cmd_version,
|
||||
}
|
||||
|
||||
def handle_command(self):
|
||||
command_text = self.input_line.text()
|
||||
self.input_line.clear()
|
||||
|
||||
self.output_area.append(f"> {command_text}")
|
||||
parts = command_text.strip().split()
|
||||
if not parts:
|
||||
return
|
||||
|
||||
command_name = parts[0]
|
||||
args = parts[1:]
|
||||
|
||||
func = self.commands.get(command_name)
|
||||
if func:
|
||||
try:
|
||||
result = func(*args)
|
||||
if result:
|
||||
self.output_area.append(str(result))
|
||||
except Exception as e:
|
||||
self.output_area.append(f"[Error] {e}")
|
||||
else:
|
||||
self.output_area.append(f"[Unknown command] '{command_name}'")
|
||||
|
||||
|
||||
def cmd_hello(self, *args):
|
||||
return "Hello from the terminal!"
|
||||
|
||||
def cmd_help(self, *args):
|
||||
return f"Available commands: {', '.join(self.commands.keys())}"
|
||||
|
||||
def cmd_version(self, *args):
|
||||
return f"{CURRENT_VERSION}"
|
||||
Reference in New Issue
Block a user