Velocity/core/utils.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-03-14 07:21:55 +00:00
from sys import exit
import curses
2022-03-15 15:37:38 +00:00
def goodbye(stdscr, data):
2022-03-14 07:21:55 +00:00
# The prompt message
2022-03-15 22:12:52 +00:00
saved = "All changes are saved."
prompt = "Really quit? (y or n): "
2022-03-14 07:21:55 +00:00
# Clear the bottom line
2022-03-15 22:12:52 +00:00
stdscr.addstr(data["height"] - 1, 0, " " * (data["width"] - 1), curses.color_pair(1))
2022-03-14 07:21:55 +00:00
# Print the prompt
2022-03-15 22:12:52 +00:00
stdscr.addstr(data["height"] - 1, 0, prompt, curses.color_pair(11))
2022-03-14 07:21:55 +00:00
# Wait for and capture a key press from the user
key = stdscr.getch()
if key == ord("y"):
# Only exit if the key was "y", a confirmation
exit()
# Clear the bottom line again
2022-03-15 22:12:52 +00:00
stdscr.addstr(data["height"] - 1, 0, " " * (data["width"] - 1), curses.color_pair(1))
2022-03-14 07:21:55 +00:00
2022-03-15 15:37:38 +00:00
def error(stdscr, data, error_msg):
# Print the error message to the bottom line
error_msg = f"ERROR: {error_msg}"
2022-03-15 22:12:52 +00:00
stdscr.addstr(data["height"] - 1, 0, error_msg, curses.color_pair(3))
stdscr.addstr(data["height"] - 1, len(error_msg) + 1, "(press any key) ", curses.color_pair(1))
2022-03-15 15:37:38 +00:00
# Wait for a key to be pressed
stdscr.getch()
# Clear the bottom line
2022-03-15 22:12:52 +00:00
stdscr.addstr(data["height"] - 1, 0, " " * (data["width"] - 1), curses.color_pair(1))