aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst92@gmail.com>2022-05-16 18:19:14 +0200
committerJulian Hurst <julian.hurst92@gmail.com>2022-05-16 18:19:14 +0200
commit7c28c776accb0c4e717403b75a38d22a472049ec (patch)
treed7015d9211b4eff30a41e7e20ef892b100061254
parent9740eee555cac43cc27e08a39a38e09a96ecb002 (diff)
downloadilhare-7c28c776accb0c4e717403b75a38d22a472049ec.tar.gz
Hide/show cursor
-rw-r--r--libui/libui.ha15
1 files changed, 14 insertions, 1 deletions
diff --git a/libui/libui.ha b/libui/libui.ha
index 7e40a9d..b0d0ea3 100644
--- a/libui/libui.ha
+++ b/libui/libui.ha
@@ -37,11 +37,21 @@ export fn init() ttyui = {
tty::makeraw(&term)!;
tty::noecho(&term)!;
- return ttyui {
+ let ui = ttyui {
term = term,
f = f,
listeners = [],
};
+ hidecursor(ui);
+ return ui;
+};
+
+export fn hidecursor(ui: ttyui) void = {
+ print(ui, "\x1B[?25l");
+};
+
+export fn showcursor(ui: ttyui) void = {
+ print(ui, "\x1B[?25h");
};
// Returns the window size for the given ttyui.
@@ -51,6 +61,7 @@ export fn getwinsize(ui: ttyui) (tty::ttysize | tty::error) = {
// Suspend the UI. To restore it, use [[resume]].
export fn suspend(ui: *ttyui) void = {
+ showcursor(*ui);
tty::termios_restore(&ui.term);
};
@@ -58,11 +69,13 @@ export fn suspend(ui: *ttyui) void = {
export fn resume(ui: *ttyui) void = {
tty::makeraw(&ui.term)!;
tty::noecho(&ui.term)!;
+ hidecursor(*ui);
};
// Restores the UI state and closes and frees the resources associated with the
// given ttyui.
export fn finish(ui: *ttyui) void = {
+ showcursor(*ui);
tty::termios_restore(&ui.term);
io::close(ui.f)!;
free(ui.listeners);