summaryrefslogtreecommitdiff
path: root/ui.ha
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-11-12 01:00:48 +0000
committerubq323 <ubq323@ubq323.website>2023-11-12 01:00:48 +0000
commit7a8a1464b3144e765f4430245e161bea39832673 (patch)
tree46122c55e4b9f6169017e0d0b76c76a07df0f0e2 /ui.ha
initial
Diffstat (limited to 'ui.ha')
-rw-r--r--ui.ha39
1 files changed, 39 insertions, 0 deletions
diff --git a/ui.ha b/ui.ha
new file mode 100644
index 0000000..31a1865
--- /dev/null
+++ b/ui.ha
@@ -0,0 +1,39 @@
+use fmt;
+use io;
+use os;
+use unix::tty;
+
+fn clear() void = {
+ fmt::fprint(os::stdout_file, "\x1b[H\x1b[2J\x1b[3J")!;
+};
+
+fn put_at(x: int, y: int, s: str) void = {
+ // 0 indexed!
+ fmt::fprintf(os::stdout_file, "\x1b[{};{}H{}", y+1,x+1, s)!;
+};
+
+fn get_key() u8 = {
+ // bad
+ let b = [0u8];
+ io::read(os::stdin_file, b)!;
+ return b[0];
+};
+
+fn setup_term() tty::termios = {
+ const term = tty::termios_query(os::stdin_file)!;
+ tty::makeraw(&term)!;
+
+ // alternate screen, hide cursor
+ fmt::fprint(os::stdout_file, "\x1b[?1049h\x1b[?25l")!;
+
+ clear();
+
+ return term;
+};
+
+fn finish_term(term: *tty::termios) void = {
+ // normal screen, show cursor
+ fmt::fprint(os::stdout_file, "\x1b[?1049l\x1b[?25h")!;
+
+ tty::termios_restore(term);
+};