fixed an issue where the entire app would crash if a command failed lol

This commit is contained in:
SpookyDervish
2025-10-26 15:29:27 +11:00
parent ff6e6cc788
commit cc80a1ddf8

17
main.py
View File

@@ -45,6 +45,7 @@ class Berry(App):
id="file-tabs" id="file-tabs"
) )
yield TextArea.code_editor(placeholder="This file is empty.", language="python", theme="css", id="code-editor", disabled=True) yield TextArea.code_editor(placeholder="This file is empty.", language="python", theme="css", id="code-editor", disabled=True)
with Vertical(id="console-container"): with Vertical(id="console-container"):
yield RichLog(id="console") yield RichLog(id="console")
yield Input(placeholder="> ", id="console-input") yield Input(placeholder="> ", id="console-input")
@@ -62,8 +63,18 @@ class Berry(App):
console = self.query_one("#console") console = self.query_one("#console")
console.write(f"> {command}") console.write(f"> {command}")
result = subprocess.check_output(command, shell=True, text=True)
console.write(result) if command == "clear" or command == "cls":
console.clear()
else:
try:
result = subprocess.check_output(command, shell=True, text=True)
console.write(result)
except subprocess.CalledProcessError as e:
console.write(e.stdout)
self.query_one("#console-input").focus()
def action_find(self): def action_find(self):
try: try:
@@ -177,6 +188,8 @@ class Berry(App):
code_editor.language = None code_editor.language = None
code_editor.disabled = False code_editor.disabled = False
code_editor.focus()
@on(Window.Minimized) @on(Window.Minimized)
def window_minimized(self, event: Window.Minimized): def window_minimized(self, event: Window.Minimized):