2022-03-17 21:47:19 +00:00
|
|
|
from core import utils, buffer
|
|
|
|
|
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
def cursor_mode(mode):
|
|
|
|
if mode == "block":
|
|
|
|
print("\033[2 q")
|
2022-03-15 15:37:38 +00:00
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
elif mode == "line":
|
2022-03-15 15:37:38 +00:00
|
|
|
print("\033[6 q")
|
|
|
|
|
|
|
|
elif mode == "hidden":
|
|
|
|
print('\033[? 25l')
|
|
|
|
|
|
|
|
elif mode == "visible":
|
|
|
|
print('\033[? 25h')
|
|
|
|
|
|
|
|
|
|
|
|
def check_cursor(data):
|
2022-03-17 21:47:19 +00:00
|
|
|
if data["cursor_y"] + data["visible_y"] == len(data["buffer_list"]):
|
2022-03-17 18:46:04 +00:00
|
|
|
data["cursor_y"] -= 1
|
|
|
|
|
2022-03-17 21:47:19 +00:00
|
|
|
if data["cursor_y"] == data["height"] - 2 and not data["cursor_y"] + data["visible_y"] == len(data["buffer_list"]):
|
|
|
|
data["visible_y"] += 1
|
|
|
|
|
|
|
|
elif data["cursor_y"] == 0 and data["buffer_list"][data["visible_y"]] != data["buffer_list"][0]:
|
|
|
|
data["visible_y"] -= 1
|
|
|
|
|
2022-03-17 18:46:04 +00:00
|
|
|
elif data["cursor_x"] > len(data["buffer_list"][data["cursor_y"]]):
|
|
|
|
data["cursor_x"] = len(data["buffer_list"][data["cursor_y"]])
|
|
|
|
|
2022-03-15 15:37:38 +00:00
|
|
|
data["cursor_x"] = max(2, data["cursor_x"])
|
|
|
|
data["cursor_x"] = min(data["width"] - 1, data["cursor_x"])
|
|
|
|
data["cursor_y"] = max(0, data["cursor_y"])
|
|
|
|
data["cursor_y"] = min(data["height"] - 3, data["cursor_y"])
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2022-03-17 21:47:19 +00:00
|
|
|
def move(screen, data):
|
2022-03-15 15:37:38 +00:00
|
|
|
# Calculate a valid cursor position from data
|
|
|
|
data = check_cursor(data)
|
|
|
|
|
|
|
|
# Move the cursor
|
2022-03-17 21:47:19 +00:00
|
|
|
screen.move(data["cursor_y"], data["cursor_x"])
|