😎 Improve modularisation x2

This commit is contained in:
Maddie H 2022-04-17 10:48:40 +01:00
parent 36db673a6b
commit 9fa83dd52b
3 changed files with 25 additions and 17 deletions

View File

@ -1,6 +1,7 @@
from core import utils
import curses import curses
from core import utils
class StatusBar: class StatusBar:
def __init__(self, instance): def __init__(self, instance):

View File

@ -1,10 +1,11 @@
from core.colors import Codes as c
import traceback
from pathlib import Path
import curses import curses
import json import json
import sys
import os import os
import sys
import traceback
from pathlib import Path
from core.colors import Codes as Col
def clear(instance, y: int, x: int): def clear(instance, y: int, x: int):
@ -130,7 +131,7 @@ def prompt(instance, message: str, color: int = 1) -> (list, None):
instance.screen.addstr(instance.height - 1, len(message), input_text) instance.screen.addstr(instance.height - 1, len(message), input_text)
def press_key_to_continue(instance, message: str): def press_key_to_continue(instance, message: str, color: int = None):
# Hide the cursor # Hide the cursor
curses.curs_set(0) curses.curs_set(0)
@ -138,7 +139,7 @@ def press_key_to_continue(instance, message: str):
clear(instance, instance.height - 1, 0) clear(instance, instance.height - 1, 0)
# Write the entire message to the screen # Write the entire message to the screen
instance.screen.addstr(instance.height - 1, 0, message, curses.color_pair(3)) instance.screen.addstr(instance.height - 1, 0, message, curses.color_pair(color or 1))
instance.screen.addstr(instance.height - 1, len(message) + 1, f"(press any key)") instance.screen.addstr(instance.height - 1, len(message) + 1, f"(press any key)")
# Wait for a keypress # Wait for a keypress
@ -156,7 +157,7 @@ def error(instance, message: str):
error_message = f"ERROR: {message}" error_message = f"ERROR: {message}"
# Create a prompt # Create a prompt
press_key_to_continue(instance, error_message) press_key_to_continue(instance, error_message, 3)
def fatal_error(exception: Exception): def fatal_error(exception: Exception):
@ -164,8 +165,8 @@ def fatal_error(exception: Exception):
curses.endwin() curses.endwin()
# Print the error message and traceback # Print the error message and traceback
print(f"{c.red}FATAL ERROR:{c.end} " print(f"{Col.red}FATAL ERROR:{Col.end} "
f"{c.yellow}{exception}{c.end}\n") f"{Col.yellow}{exception}{Col.end}\n")
print(traceback.format_exc()) print(traceback.format_exc())
# Exit, with an error exit code # Exit, with an error exit code

View File

@ -6,16 +6,22 @@ def execute(instance, commands: list):
if commands: if commands:
# Check each command in the list of commands # Check each command in the list of commands
for command in commands: for command in commands:
if command == "w": # Write
# Write to the file
pass
if command == "d": # Debug if command == "d": # Debug
# Create the debug prompt # Create the debug prompt
utils.prompt(instance, f"*Whawt awe uwu doing tuwu me mastew?* " utils.press_key_to_continue(instance, f"Cursor: {instance.cursor} Raw: {instance.raw_cursor} "
f"Cursor: {instance.cursor} Raw: {instance.raw_cursor} "
f"Len: {len(instance.buffer.data)}") f"Len: {len(instance.buffer.data)}")
elif command == "t": # Toggle
# Toggle the status bar theme
if instance.components.components["bottom"][0].theme == "default":
instance.components.components["bottom"][0].theme = "inverted"
else:
instance.components.components["bottom"][0].theme = "default"
elif command == "w": # Write
# Write to the file
pass
elif command == "q": # Quit elif command == "q": # Quit
# Create a goodbye prompt # Create a goodbye prompt
utils.goodbye(instance) utils.goodbye(instance)