aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-04-07 04:14:51 +0100
committerdam <dam@gudinoff>2024-04-07 04:14:51 +0100
commit7ddda0dac4b75adc30799eb1a36a84ecc1e41a86 (patch)
treeaaf8a214018b96637f275a19fde913e16e176a28
parentb3a25d8ef20c98f4bcf917f23d546e54cf41cd35 (diff)
downloadtask-time-tracker-7ddda0dac4b75adc30799eb1a36a84ecc1e41a86.tar.zst
task-time-tracker-7ddda0dac4b75adc30799eb1a36a84ecc1e41a86.zip
Replaced row/column arguments by x/y which are more familiar.
-rw-r--r--modules/TUI/module.jai34
-rw-r--r--ttt.jai118
2 files changed, 76 insertions, 76 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 764effe..5b7861e 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -447,14 +447,14 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
// TODO Some of these may be nice to have:
// > https://unix.stackexchange.com/questions/255707/what-are-the-keyboard-shortcuts-for-the-command-line
- row, col := get_cursor_position();
+ x, y := get_cursor_position();
write_strings(Commands.StartBlinking, Commands.BlinkingBarShape);
// Clear line for input.
for 1..count_limit {
print_character(#char " ");
}
- set_cursor_position(row, col);
+ set_cursor_position(x, y);
key := Keys.None;
while true {
@@ -513,17 +513,17 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
}
if is_visible {
- set_cursor_position(row, col);
+ set_cursor_position(x, y);
write_string(str);
for str.count..count_limit-1 print_character(#char " ");
}
else {
- set_cursor_position(row, col);
+ set_cursor_position(x, y);
for 0..str.count-1 print_character(#char "*");
for str.count..count_limit-1 print_character(#char " ");
}
- set_cursor_position(row, col+idx);
+ set_cursor_position(x+idx, y);
}
write_strings(Commands.StopBlinking, Commands.DefaultShape);
@@ -535,6 +535,8 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
start :: () {
if active == true return;
+ // TODO Should start() call flush_input internally?
+
setup_key_map(); // TODO This is being called multiple times... please fix me!
input_string.data = input_buffer.data;
@@ -625,7 +627,7 @@ clear_terminal :: inline () {
}
// TODO Maybe rename to "get_size()"
-get_terminal_size :: () -> rows: int, columns: int {
+get_terminal_size :: () -> width: int, height: int {
assert_is_active();
auto_release_temp();
@@ -659,27 +661,25 @@ get_terminal_size :: () -> rows: int, columns: int {
rows = parse_int(*parts[1]);
columns = parse_int(*parts[2]);
}
- // Some systems don't allow to query the terminal size directly.
+ // Some systems don't allow to query the terminal size directly... or the answer takes too much time.
// In such cases, measure it indirectly by the maximum possible cursor position.
else {
- flush_input();
- cursor_row, cursor_column := get_cursor_position();
- defer set_cursor_position(cursor_row, cursor_column);
+ x, y := get_cursor_position();
+ defer set_cursor_position(x, y);
set_cursor_position(0xFFFF, 0xFFFF);
- rows, columns = get_cursor_position();
+ columns, rows = get_cursor_position();
}
- return rows, columns;
+ return columns, rows;
}
-set_cursor_position :: (row: int, column: int) {
+set_cursor_position :: (x: int, y: int) {
assert_is_active();
- auto_release_temp();
- print(Commands.SetCursorPosition, row, column);
+ print(Commands.SetCursorPosition, y, x);
}
-get_cursor_position :: () -> row: int, column: int {
+get_cursor_position :: () -> x: int, y: int {
assert_is_active();
auto_release_temp();
@@ -710,7 +710,7 @@ get_cursor_position :: () -> row: int, column: int {
parts := split(input, ";",, temporary_allocator);
row := parse_int(*parts[0]);
column := parse_int(*parts[1]);
- return row, column;
+ return column, row;
}
set_terminal_title :: (title: string) {
diff --git a/ttt.jai b/ttt.jai
index 8c8d31c..88f1323 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -153,13 +153,13 @@ draw_error_window :: () {
TUI.using_style(style_error);
TUI.draw_box(pos_x, pos_y, w_size_x, w_size_y);
- TUI.set_cursor_position(pos_y, pos_x + 1);
+ TUI.set_cursor_position(pos_x + 1, pos_y);
write_string(" Error ");
- TUI.set_cursor_position(pos_y + 1, pos_x + 1);
+ TUI.set_cursor_position(pos_x + 1, pos_y + 1);
for 1..w_size_x-2 {
print_character(#char " ");
}
- TUI.set_cursor_position(pos_y + 1, pos_x + 1);
+ TUI.set_cursor_position(pos_x + 1, pos_y + 1);
write_string(error_message);
}
@@ -272,7 +272,7 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int {
}
}
- TUI.set_cursor_position(y, x);
+ TUI.set_cursor_position(x, y);
if time < 0 {
print_padding(left_padding);
@@ -980,13 +980,13 @@ draw_tui :: (db: *Database, layout: *Layout) {
for 0..layout.columns.count-2 {
column := layout.columns[it];
x += 1 + column.width;
- TUI.set_cursor_position(y, x);
+ TUI.set_cursor_position(x, y);
write_string(TUI.Drawings.TeeT);
for row: 2..size_y {
- TUI.set_cursor_position(row, x);
+ TUI.set_cursor_position(x, row);
write_string(TUI.Drawings.LineV);
}
- TUI.set_cursor_position(size_y, x);
+ TUI.set_cursor_position(x, size_y);
write_string(TUI.Drawings.TeeB);
}
write_string(TUI.Commands.TextMode);
@@ -1001,7 +1001,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
x += 1;
col = *layout.columns[L_TITLE_IDX];
//mvaddstr(xx y, xx (x + col.alignment_offset), ifx db == *archive then layout.archive_title.data else col.header.data); TODO DAM
- TUI.set_cursor_position(y, x + col.alignment_offset);
+ TUI.set_cursor_position(x + col.alignment_offset, y);
write_string(ifx db == *archive then layout.archive_title else col.header);
x += col.width;
@@ -1022,7 +1022,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
}
col = *layout.columns[L_DAYS_IDX + idx];
//mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data); TODO DAM
- TUI.set_cursor_position(y, x + col.alignment_offset);
+ TUI.set_cursor_position(x + col.alignment_offset, y);
write_string(col.header);
x += col.width;
}
@@ -1032,7 +1032,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
x += 1;
col = *layout.columns[L_TOTAL_IDX];
//mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data); TODO DAM
- TUI.set_cursor_position(y, x + col.alignment_offset);
+ TUI.set_cursor_position(x + col.alignment_offset, y);
write_string(col.header);
@@ -1069,14 +1069,14 @@ draw_tui :: (db: *Database, layout: *Layout) {
column_width = layout.columns[L_TITLE_IDX].width;
// mvprintw(xx y, xx x, "%-*.*s", column_width, column_width, temp_c_string(xx task.name)); //task.name); TODO Fix required for LLVM/Cncurses. TODO DAM
// TODO FIXME OH MY GOD SUCH BAD CODEZ
- TUI.set_cursor_position(y, x);
+ TUI.set_cursor_position(x, y);
white_spaces := column_width;
// FIXME Improve by using buffer instead of printing one char at the time.
while white_spaces > 0 {
print_character(#char " ");
white_spaces -= 1;
}
- TUI.set_cursor_position(y, x);
+ TUI.set_cursor_position(x, y);
task_name: string = cast(string)task.name;
task_name.count = ifx task_name.count > column_width then column_width else task_name.count;
print("%", task_name);
@@ -1107,7 +1107,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
///////////////////////////////////////////////////////////////////////////
// Draw selected/total tasks.
size := 1 + count_digits(db.selected_idx + 1) + 1 + count_digits(db.tasks.count) + 1; // " XXX/YYY "
- TUI.set_cursor_position(size_y, 2);
+ TUI.set_cursor_position(2, size_y);
if (size <= layout.columns[L_TITLE_IDX].width) {
print(" %/% ", db.selected_idx + 1, db.tasks.count);
}
@@ -1157,61 +1157,64 @@ free_memory :: () {
//reset_temporary_storage();
}
-read_input_string :: (row: int, column: int, input_limit: int, padding: int = 0) -> value: string, success: bool {
+read_input_string :: (x: int, y: int, input_limit: int, padding: int = 0) -> value: string, success: bool {
// TODO Draw padding (at end of inputbox)... padding was renamed to input_width... is this the best name?
// TODO Maybe add another optional arg with the placeholder text (to be preset on the input)?
- column += 1; // TODO FIX THE NCURSES INDEXING CHAOS
-
- TUI.set_cursor_position(row, column + input_limit);
+ TUI.set_cursor_position(x + input_limit, y);
write_string(TUI.Commands.DrawingMode);
for 1..padding {
write_string(TUI.Drawings.Checkerboard);
}
write_string(TUI.Commands.TextMode);
- TUI.set_cursor_position(row, column);
+ TUI.set_cursor_position(x, y);
value, key := TUI.read_input_line(input_limit);
return value, key == TUI.Keys.Enter;
}
// Returns success.
-read_input_int :: (row: int, message: string) -> value: int, success: bool {
- TUI.set_cursor_position(row, 2);
+read_input_int :: (y: int, message: string) -> value: int, success: bool {
+ x :: 3;
+
+ // Draw checkerboard.
+ TUI.set_cursor_position(2, y);
write_string(TUI.Commands.DrawingMode);
- for 1..size_x-2 {
+ for 2..x {
print(TUI.Drawings.Checkerboard);
}
write_string(TUI.Commands.TextMode);
- TUI.set_cursor_position(row, 3);
+ TUI.set_cursor_position(x, y);
write_strings(" ", message, " ");
-
- // Get line number.
- input_pos_x := 1 + 1 + 1 + message.count + 1;
- input_width := size_x - input_pos_x - 1;
+ input_pos_x := x + message.count + 2;
+ input_width := size_x - input_pos_x - 1;
+
style_input := context.tui_style;
style_input.underline = true;
TUI.using_style(style_input);
- str := read_input_string(row, input_pos_x, input_width);
+ str := read_input_string(input_pos_x, y, input_width);
value, success := parse_int(*str);
return value, success;
}
// Shows message to user and waits for user key press.
-prompt_user_key :: (row: int, message: string) -> TUI.Key {
- TUI.set_cursor_position(row, 2);
+prompt_user_key :: (y: int, message: string) -> TUI.Key {
+ x :: 3;
+
+ // Draw checkerboard.
+ TUI.set_cursor_position(2, y);
write_string(TUI.Commands.DrawingMode);
for 1..size_x-2 {
print(TUI.Drawings.Checkerboard);
}
write_string(TUI.Commands.TextMode);
- TUI.set_cursor_position(row, 3);
+ TUI.set_cursor_position(x, y);
write_strings(" ", message, " ");
return TUI.get_key();
}
@@ -1234,19 +1237,19 @@ main :: () {
}
next_line :: inline () {
- r, c := TUI.get_cursor_position();
- TUI.set_cursor_position(r+1, 1);
+ x, y := TUI.get_cursor_position();
+ TUI.set_cursor_position(1, y+1);
}
if perform_test && 1 {
print("TEST : set and get cursor position\n", to_standard_error = true);
TUI.start();
- ROW :: 3;
- COLUMN :: 3;
- TUI.set_cursor_position(ROW, COLUMN);
- row, column := TUI.get_cursor_position();
+ X :: 2;
+ Y :: 3;
+ TUI.set_cursor_position(X, Y);
+ x, y := TUI.get_cursor_position();
TUI.stop();
- assert_result(row == ROW && column == COLUMN, "Failed set/get cursor position.\n");
+ assert_result(x == X && y == Y, "Failed set/get cursor position.\n");
}
if perform_test && 1 {
@@ -1278,7 +1281,7 @@ main :: () {
if perform_test && 1 {
print("TEST : draw box\n", to_standard_error = true);
auto_release_temp();
- TUI.start(); // TODO Should start() call flush_input internally?
+ TUI.start();
TUI.flush_input();
TUI.clear_terminal();
TUI.draw_box(1, 2, 5, 3);
@@ -1294,9 +1297,9 @@ main :: () {
auto_release_temp();
TUI.start();
TUI.clear_terminal();
- rows, columns := TUI.get_terminal_size();
+ width, height := TUI.get_terminal_size();
TUI.set_cursor_position(1, 1);
- print("Is terminal size % columns and % rows? (y/n)", columns, rows);
+ print("Is terminal size %x%? (y/n)", width, height);
key: TUI.Key = xx TUI.Keys.None;
while (key == xx TUI.Keys.None || key == xx TUI.Keys.Resize) {
key = TUI.get_key();
@@ -1328,9 +1331,9 @@ main :: () {
key: TUI.Key = #char "d";
last_none_char := "X";
- size_r, size_c := TUI.get_terminal_size();
+ width, height := TUI.get_terminal_size();
TUI.clear_terminal();
- TUI.draw_box(1, 1, size_c, size_r);
+ TUI.draw_box(1, 1, width, height);
drop_down := 0;
while(key != #char "q") {
@@ -1344,14 +1347,14 @@ main :: () {
case TUI.Keys.Resize; #through;
case #char "c"; {
- size_r, size_c = TUI.get_terminal_size();
+ width, height = TUI.get_terminal_size();
TUI.clear_terminal();
- TUI.draw_box(1, 1, size_c, size_r);
+ TUI.draw_box(1, 1, width, height);
drop_down = 0;
}
case; {
- TUI.set_cursor_position(3+drop_down, 2);
+ TUI.set_cursor_position(2, 3+drop_down);
str := TUI.to_string(key);
array_to_print: [..] string;
for 0..str.count-1 {
@@ -1371,12 +1374,11 @@ main :: () {
}
}
-
- x := ifx size_r > 1 then size_r-1 else 1;
- y := ifx size_c > 24 then size_c-24 else 1;
+ x := ifx width > 24 then width-24 else 1;
+ y := ifx height > 1 then height-1 else 1;
TUI.set_cursor_position(x, y);
- print("size(CxR): %x%\n", size_c, size_r);
+ print("size = %x%\n", width, height);
key = TUI.get_key(1000);
// __mark := get_temporary_storage_mark();
@@ -1395,7 +1397,7 @@ main :: () {
print("Enter some text (use Enter to finish, Esc to cancel, or resize to abort):");
next_line();
str, key := TUI.read_input_line(15);
- TUI.set_cursor_position(3, 1);
+ TUI.set_cursor_position(1, 3);
error_message: string;
if key == {
case TUI.Keys.Escape; {
@@ -1427,7 +1429,7 @@ main :: () {
print("Enter some secret (use Enter to finish, Esc to cancel, or resize to abort):");
next_line();
str, key := TUI.read_input_line(15, false);
- TUI.set_cursor_position(3, 1);
+ TUI.set_cursor_position(1, 3);
error_message: string;
if key == {
case TUI.Keys.Escape; {
@@ -1645,7 +1647,7 @@ main :: () {
if (is_terminal_too_small) {
INVALID_WINDOW_MESSAGE :: "Terminal is too small: minimum 60x3.";
- TUI.set_cursor_position(size_y / 2, (size_x - INVALID_WINDOW_MESSAGE.count) / 2);
+ TUI.set_cursor_position((size_x - INVALID_WINDOW_MESSAGE.count) / 2, size_y / 2);
write_strings(INVALID_WINDOW_MESSAGE);
}
else {
@@ -1691,7 +1693,7 @@ main :: () {
// When terminal is resized.
case TUI.Keys.Resize;
TUI.clear_terminal();
- size_y, size_x = TUI.get_terminal_size();
+ size_x, size_y = TUI.get_terminal_size();
is_terminal_too_small = size_x < 60 || size_y < 3;
update_layout();
layout = *layouts[ifx size_x > 100 then Layouts.NORMAL else Layouts.COMPACT];
@@ -1742,9 +1744,8 @@ main :: () {
if (selected_task == null) continue;
// Change task name.
- // TODO WIPWIPWIP
TUI.using_style(action_style);
- input := read_input_string(selected_task_row, 1, Task.name.count, size_x - 2 - Task.name.count);
+ input := read_input_string(2, selected_task_row, Task.name.count, size_x - 2 - Task.name.count);
if is_empty_string(input) == false {
replace_chars(input, "\t\x0B\x0C\r", #char " "); // Replace weird spaces with space.
memset(selected_task.name.data, 0, Task.name.count);
@@ -1784,16 +1785,15 @@ main :: () {
// Prepare position to input time operation.
selected_day := cast(int)(key - #char "1"); // TODO DAM this cast...
input_width := layout.columns[L_DAYS_IDX + selected_day].width;
- input_pos_x := 1 + layout.columns[L_TITLE_IDX].width;
-
+ input_pos_x := 2 + layout.columns[L_TITLE_IDX].width;
for 0..selected_day-1 {
input_pos_x += 1 + layout.columns[L_DAYS_IDX + it].width;
}
input_pos_x += 1;
-
+
// Get input string.
TUI.using_style(action_style);
- input := read_input_string(selected_task_row, input_pos_x, input_width); // TODO Temp stringzes.
+ input := read_input_string(input_pos_x, selected_task_row, input_width); // TODO Temp stringzes.
// Abort if input if empty.
if is_empty_string(input) continue;