2022-03-15 15:37:38 +00:00
|
|
|
from core import statusbar, cursor
|
2022-03-17 21:47:19 +00:00
|
|
|
import curses
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
|
2022-03-15 15:37:38 +00:00
|
|
|
def execute(data, key):
|
2022-03-14 07:21:55 +00:00
|
|
|
if key == ord("j"):
|
|
|
|
# Move the cursor down
|
|
|
|
data["cursor_y"] += 1
|
|
|
|
|
|
|
|
elif key == ord("k"):
|
|
|
|
# Move the cursor up
|
|
|
|
data["cursor_y"] -= 1
|
|
|
|
|
|
|
|
elif key == ord("l"):
|
|
|
|
# Move the cursor right
|
|
|
|
data["cursor_x"] += 1
|
|
|
|
|
|
|
|
elif key == ord("h"):
|
|
|
|
# Move the cursor left
|
|
|
|
data["cursor_x"] -= 1
|
|
|
|
|
|
|
|
elif key == ord("i"):
|
2022-03-15 15:37:38 +00:00
|
|
|
# Exit normal mode and enter insert mode
|
|
|
|
data["mode"] = "insert"
|
2022-03-14 07:21:55 +00:00
|
|
|
|
2022-03-15 22:12:52 +00:00
|
|
|
elif key == ord("I"):
|
|
|
|
# Exit normal mode and enter insert mode
|
|
|
|
data["cursor_x"] += 1
|
|
|
|
data["mode"] = "insert"
|
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
elif key in (ord(":"), ord(";")):
|
2022-03-15 15:37:38 +00:00
|
|
|
# Exit normal mode and enter command mode
|
|
|
|
data["mode"] = "command"
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2022-03-17 21:47:19 +00:00
|
|
|
def activate(screen, data):
|
2022-03-14 07:21:55 +00:00
|
|
|
# Refresh the status bar
|
2022-03-17 21:47:19 +00:00
|
|
|
statusbar.refresh(screen, data)
|
2022-03-15 15:37:38 +00:00
|
|
|
|
|
|
|
# Move the cursor
|
2022-03-17 21:47:19 +00:00
|
|
|
cursor.move(screen, data)
|
2022-03-15 15:37:38 +00:00
|
|
|
|
|
|
|
# Switch the cursor to a block
|
|
|
|
cursor.cursor_mode("block")
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
# Wait for and capture a key press from the user
|
2022-03-17 21:47:19 +00:00
|
|
|
key = screen.getch()
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
# Check against the keybindings
|
2022-03-15 15:37:38 +00:00
|
|
|
data = execute(data, key)
|
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
return data
|