Velocity/core/modes.py

35 lines
909 B
Python
Raw Normal View History

2022-03-19 15:13:28 +00:00
from mode import normal, insert, command
2022-03-19 15:41:40 +00:00
def activate(instance, mode):
2022-03-19 15:13:28 +00:00
# Visibly update the mode
instance.mode = mode
# Refresh the screen
instance.refresh()
2022-03-19 15:13:28 +00:00
if mode == "command":
2022-03-19 15:41:40 +00:00
# Activate command mode
instance.components.components["bottom"][0].colors[1] = 5
2022-03-19 15:41:40 +00:00
command.activate(instance)
2022-03-19 15:13:28 +00:00
elif mode == "insert":
2022-03-19 15:41:40 +00:00
# Activate insert mode
2022-04-15 16:38:39 +01:00
instance.components.components["bottom"][0].colors[1] = 11
2022-03-19 15:57:38 +00:00
insert.activate()
2022-03-19 15:13:28 +00:00
elif mode == "normal":
2022-03-19 15:41:40 +00:00
# Activate normal mode
instance.components.components["bottom"][0].colors[1] = 5
2022-03-19 15:57:38 +00:00
normal.activate()
2022-03-19 15:13:28 +00:00
def handle_key(instance, key):
2022-03-19 15:41:40 +00:00
# Normal mode - default keybindings
2022-03-19 15:13:28 +00:00
if instance.mode == "normal":
2022-03-19 15:41:40 +00:00
normal.execute(instance, key)
2022-03-19 15:13:28 +00:00
# Insert mode - inserting text to the buffer
elif instance.mode == "insert":
2022-03-19 15:41:40 +00:00
insert.execute(instance, key)