Velocity/mode/normal.py

46 lines
1.1 KiB
Python
Raw Normal View History

import curses
from core import cursors, modes, utils
2022-03-19 15:13:28 +00:00
def execute(instance, key):
if key == curses.BUTTON1_CLICKED:
# Move the cursor to the position clicked
utils.prompt(instance, str(curses.getmouse()))
elif key in (ord("j"), curses.KEY_DOWN):
2022-03-19 15:13:28 +00:00
# Move the cursor down
2022-03-19 19:19:25 +00:00
cursors.push(instance, "down")
2022-03-19 15:13:28 +00:00
elif key in (ord("k"), curses.KEY_UP):
2022-03-19 15:13:28 +00:00
# Move the cursor up
2022-03-19 19:19:25 +00:00
cursors.push(instance, "up")
2022-03-19 15:13:28 +00:00
elif key in (ord("l"), curses.KEY_RIGHT):
2022-03-19 15:13:28 +00:00
# Move the cursor right
2022-03-19 19:19:25 +00:00
cursors.push(instance, "right")
2022-03-19 15:13:28 +00:00
elif key in (ord("h"), curses.KEY_LEFT):
2022-03-19 15:13:28 +00:00
# Move the cursor left
2022-03-19 19:19:25 +00:00
cursors.push(instance, "left")
2022-03-19 15:13:28 +00:00
elif key == ord("i"):
# Activate insert mode
2022-03-19 15:41:40 +00:00
modes.activate(instance, "insert")
2022-03-19 15:13:28 +00:00
elif key == ord("I"):
# Move the cursor to the right
2022-03-19 19:19:25 +00:00
cursors.push(instance, "right")
2022-03-19 15:13:28 +00:00
# Then activate insert mode
2022-03-19 15:41:40 +00:00
modes.activate(instance, "insert")
2022-03-19 15:13:28 +00:00
elif key in (ord(":"), ord(";")):
# Activate command mode
2022-03-19 15:41:40 +00:00
modes.activate(instance, "command")
2022-03-19 15:13:28 +00:00
2022-03-19 15:41:40 +00:00
def activate():
2022-03-19 15:13:28 +00:00
# Switch the cursor to a block
2022-03-19 19:19:25 +00:00
cursors.mode("block")