Velocity/mode/command.py

42 lines
1.4 KiB
Python
Raw Normal View History

2022-03-19 15:13:28 +00:00
from core import utils
def execute(instance, commands: list):
2022-03-19 15:41:40 +00:00
# Only if commands are given
if commands:
# Check each command in the list of commands
for command in commands:
if command == "d": # Debug
# Create the debug prompt
2022-04-17 10:48:40 +01:00
utils.press_key_to_continue(instance, f"Cursor: {instance.cursor} Raw: {instance.raw_cursor} "
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
# Create a goodbye prompt
2022-03-19 15:41:40 +00:00
utils.goodbye(instance)
2022-03-19 15:13:28 +00:00
else: # Invalid command
utils.error(instance, f"invalid command: '{command}'")
2022-03-19 15:13:28 +00:00
def activate(instance):
2022-03-19 15:41:40 +00:00
# Create a prompt, which returns the input (commands)
2022-03-19 15:13:28 +00:00
commands = utils.prompt(instance, ":")
2022-03-19 15:41:40 +00:00
# Execute the commands given
execute(instance, commands)
2022-03-19 15:13:28 +00:00
2022-03-19 15:41:40 +00:00
# Return to normal mode once all commands are executed
2022-03-19 15:13:28 +00:00
instance.mode = "normal"