aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai114
1 files changed, 75 insertions, 39 deletions
diff --git a/ttt.jai b/ttt.jai
index 49e88eb..b8681ff 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1182,36 +1182,40 @@ read_enter_confirmation :: inline (row: int, style: int, message: string) -> boo
main :: () {
// -- -- -- Testing TUI -- START
- #if 0 {
- print("test 0\n");
- TUI.test();
- return;
- }
+
+ // TODO Test input
#if 0 {
print("test 1\n");
TUI.start();
buffer: [8] u8;
- brss, error, msg := TUI.OS_read_input(buffer.data, buffer.count);
+ bytes_read, error, error_msg := TUI.OS_read_input(buffer.data, buffer.count);
TUI.stop();
- if error == true print("error:%", msg);
- print("br:%", brss);
- print("input:%", cast(string)buffer);
+ if error == true print("error:%\n", error_msg);
+ print("read % bytes:", bytes_read);
+ for 0..bytes_read-1 {
+ char := "-NA-";
+ if buffer[it] >= 33 && buffer[it] <= 126 {
+ char.data = *buffer[it];
+ char.count = 1;
+ }
+ print(" 0x% (%)", FormatInt.{minimum_digits=2, base=10, value=buffer[it]}, char);
+ }
+ print("\n");
TUI.stop();
- return;
}
#if 0 {
print("test 2\n");
- key: TUI.Key = #char "d";
- while(key != #char "q") {
+ _key: TUI.Key = #char "d";
+ while(_key != #char "q") {
// key = TUI.get_key(10);
buffer: [8] u8;
buffer[0] = 0;
- brss := TUI.OS_read_input(buffer.data, 1);
- if brss > 0 {
- key = buffer[0];
- print(">%<", xx key);
+ bytes_read := TUI.OS_read_input(buffer.data, 1);
+ if bytes_read > 0 {
+ _key = buffer[0];
+ print(">%<", xx _key);
}
else {
print(":");
@@ -1219,43 +1223,72 @@ main :: () {
sleep_milliseconds(10);
}
TUI.stop();
- return;
}
- #if 0 {
- print("testing select\n");
+ if 1 {
+ print("TEST : set and get cursor position --\n", to_standard_error = true);
TUI.start();
- TUI.test();
- TUI.test();
- TUI.test();
+ ROW :: 3;
+ COLUMN :: 3;
+ TUI.set_cursor_position(ROW, COLUMN);
+ row, column := TUI.get_cursor_position();
TUI.stop();
- return;
+ assert(row == ROW && column == COLUMN, "Failed set/get cursor position.\n");
+ print("> success\n", to_standard_error = true);
}
-
- #if 0 {
- print("test 3\n");
+
+ if 1 {
+ print("TEST : test key input --\n", to_standard_error = true);
+ auto_release_temp();
TUI.start();
- key: TUI.Key = #char "d";
+ TUI.clear_terminal();
+ TUI.set_cursor_position(1, 1);
+ write_string("Press q to exit, other key to print it to screen, wait 1s to see animation.");
+ TUI.set_cursor_position(2, 1);
+ key: TUI.Key;
while(key != #char "q") {
__mark := get_temporary_storage_mark();
- // sleep_milliseconds(1000);
- key = TUI.get_key(3000);
-
- if key != xx TUI.Keys.None print_character(key);
+ key = TUI.get_key(1000);
+ if key != xx TUI.Keys.None print_character(cast,force(u8)key);
else write_string("-");
set_temporary_storage_mark(__mark);
}
- print("Waiting 1s..");
- sleep_milliseconds(1000);
- print("!\n\r");
- print("Stoping..");
TUI.stop();
- print("!\n\r");
- return;
+ print("> success\n", to_standard_error = true);
+ }
+
+ if 1 {
+ print("TEST : draw box --\n", to_standard_error = true);
+ auto_release_temp();
+ TUI.start();
+ TUI.clear_terminal();
+ TUI.draw_box(1, 2, 5, 3);
+ TUI.set_cursor_position(1, 1);
+ print("Can you see the box below? (y/n)");
+ key := TUI.get_key();
+ TUI.stop();
+ assert(key == #char "y", "Failed to draw box.\n");
+ print("> success\n", to_standard_error = true);
+ }
+
+ if 1 {
+ print("TEST : get terminal size --\n", to_standard_error = true);
+ auto_release_temp();
+ TUI.start();
+ TUI.clear_terminal();
+ rows, columns := TUI.get_terminal_size();
+ TUI.set_cursor_position(1, 1);
+ print("Is terminal size % columns and % rows? (y/n)", columns, rows);
+ key := TUI.get_key();
+ TUI.stop();
+ assert(key == #char "y", "Failed to get terminal size.\n");
+ print("> success\n", to_standard_error = true);
}
- #if 1 {
- print("test 4\n", to_standard_error = true);
+ // TODO Resizing terminal breaks the tests... try to fix it.
+
+ #if 0 {
+ print("test 5\n", to_standard_error = true);
TUI.start();
TUI.set_terminal_title("bazinga");
xcolumns, xrows: int;
@@ -1286,6 +1319,9 @@ main :: () {
}
TUI.stop();
print("size(CxR): %x%\n", xcolumns, xrows);
+ }
+
+ #if true {
return;
}