Velocity/modes/normal.py

54 lines
1.1 KiB
Python
Raw Normal View History

2022-03-15 15:37:38 +00:00
from core import statusbar, cursor
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-15 15:37:38 +00:00
def activate(stdscr, data):
2022-03-14 07:21:55 +00:00
# Refresh the status bar
2022-03-15 15:37:38 +00:00
statusbar.refresh(stdscr, data)
# Move the cursor
cursor.move(stdscr, data)
# 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
key = stdscr.getch()
# 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