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 18:46:04 +00:00
|
|
|
if data["cursor_y"] == len(data["buffer_list"]):
|
|
|
|
data["cursor_y"] -= 1
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def move(stdscr, data):
|
|
|
|
# Calculate a valid cursor position from data
|
|
|
|
data = check_cursor(data)
|
|
|
|
|
|
|
|
# Move the cursor
|
|
|
|
stdscr.move(data["cursor_y"], data["cursor_x"])
|