aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-12-21 19:57:36 +0000
committerdam <dam@gudinoff>2023-12-21 19:57:36 +0000
commitbff4f889c49587fffd39ceb04c88db42bba8d8f1 (patch)
tree61d4d073d3af4870ef22d35a7efea52ca56603cd
parent3a949ea9f18d06bbefc73da8ca0c1051252ca96d (diff)
downloadtask-time-tracker-bff4f889c49587fffd39ceb04c88db42bba8d8f1.tar.zst
task-time-tracker-bff4f889c49587fffd39ceb04c88db42bba8d8f1.zip
Started to use TUI in ttt.
-rw-r--r--TUI/module.jai20
-rw-r--r--ttt.jai72
2 files changed, 59 insertions, 33 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 0e2ff22..bb5b800 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -115,6 +115,14 @@ Keys :: struct {
// Terminal key-codes have 1 to 6 bytes, so we can signal special cases setting the edge-bytes.
None : Key : 0xF0000000_0000000F;
Resize : Key : 0xF0000000_0000001F;
+
+ Up : Key : #run to_key("\e[A");
+ Down : Key : #run to_key("\e[B");
+ Right : Key : #run to_key("\e[C");
+ Left : Key : #run to_key("\e[D");
+
+ PgUp : Key : #run to_key("\e[5~");
+ PgDown : Key : #run to_key("\e[6~");
}
/* TODO
@@ -293,12 +301,18 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
utf8_bytes := count_utf8_bytes(input_string[0]);
assert(utf8_bytes <= input_string.count, "The input buffer is too small."); // TODO Improve error message.
-
+
+ // TODO This is only being done after the OS_wait_for_input... for now!
to_parse := input_string;
to_parse.count = utf8_bytes;
- key := to_key(to_parse);
- advance(*input_string, utf8_bytes);
+ // Must be a terminal escape sequence.
+ if utf8_bytes == 1 && input_string[0] == #char "\e" {
+ to_parse.count = ifx input_string.count > 6 then 6 else input_string.count; // TODO We should look into the input_string and search for the following escape sequence or somehting!?
+ }
+
+ key := to_key(to_parse);
+ advance(*input_string, to_parse.count);
return key;
/// /// /// /// /// /// /// /// ///
diff --git a/ttt.jai b/ttt.jai
index 80d89bf..11bf9f4 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -902,7 +902,7 @@ initialize_tui :: () {
}
// TODO DAM
- TIO.initialize();
+ TUI.start();
// stdscr = initscr(); // Start curses mode. TODO DAM
// cbreak(); // Line buffering disabled; pass on everty thing to me. TODO DAM
// keypad(stdscr, true); // I need those nifty F1..F12. TODO DAM
@@ -956,11 +956,10 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Reset theme and clear screen.
//attrset(A_NORMAL); TODO DAM
- TIO.tui_clear_screen();
+ TUI.clear_terminal();
// Draw outer border.
- //box(stdscr, 0, 0); TODO DAM
- // WIP
+ TUI.draw_box(1, 1, size_x, size_y);
// Draw table grids.
// TODO Maybe this could be simplified?
@@ -979,13 +978,15 @@ draw_tui :: (db: *Database, layout: *Layout) {
///////////////////////////////////////////////////////////////////////////
// Draw headers.
- y = 0;
- x = 0;
+ y = 1;
+ x = 1;
// Headers : title
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);
+ write_string(ifx db == *archive then layout.archive_title else col.header);
x += col.width;
// Headers : days
@@ -1003,6 +1004,8 @@ 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);
+ write_string(col.header);
x += col.width;
// Reset theme.
@@ -1013,6 +1016,8 @@ 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);
+ write_string(col.header);
///////////////////////////////////////////////////////////////////////////
@@ -1021,7 +1026,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
total_time := 0;
column_width: int;
- y = 0;
+ y = 1;
// Pagination based on currently selected task (show page where selected task is).
idx_start := (db.selected_idx / layout_tasks_rows) * layout_tasks_rows;
// Display up to rows allowed by the layout, or less if reached end of database.
@@ -1030,7 +1035,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
auto_release_temp(); // TODO Temporary memory being trashed?!
task := *db.tasks[task_idx];
y += 1;
- x = 0;
+ x = 1;
// Apply theme.
if (task == active_task && task == selected_task) {
@@ -1047,6 +1052,8 @@ draw_tui :: (db: *Database, layout: *Layout) {
x += 1;
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
+ TUI.set_cursor_position(y, x);
+ print("%", cast(string)task.name); // TODO Needs adjustment to fit column width.
x += column_width;
// Task times.
@@ -1072,12 +1079,16 @@ draw_tui :: (db: *Database, layout: *Layout) {
///////////////////////////////////////////////////////////////////////////
// Draw selected/total tasks.
+ // TODO Something is wrong here... sometimes it only changes to the small format on the 1001 instead of 1000. FIXME
size := 1 + count_digits(db.selected_idx + 1) + 1 + count_digits(db.tasks.count) + 1; // " XXX/YYY "
+ TUI.set_cursor_position(size_y, 2);
if (size <= layout.columns[L_TITLE_IDX].width) {
// mvprintw(size_y - 1, 1, " %td/%zd ", db.selected_idx + 1, db.tasks.count); TODO DAM
+ print(" %/% ", db.selected_idx + 1, db.tasks.count);
}
else {
// mvprintw(size_y - 1, 1, "%td", db.selected_idx + 1); TODO DAM
+ print("%", db.selected_idx + 1);
}
@@ -1274,7 +1285,13 @@ main :: () {
case; {
TUI.set_cursor_position(3+drop_down, 2);
- write_string(TUI.to_string(key));
+ str := TUI.to_string(key);
+ for 0..str.count-1 {
+ if str[it] == #char "\e" {
+ str[it] = #char "?";
+ }
+ }
+ write_string(str);
drop_down += 1;
}
}
@@ -1291,10 +1308,6 @@ main :: () {
print("size(CxR): %x%\n", xcolumns, xrows);
}
- #if true {
- return;
- }
-
// -- -- -- Testing TUI -- STOP
@@ -1481,9 +1494,9 @@ main :: () {
db := *database;
layout := *layouts[Layouts.COMPACT];
-
- //flushinp(); TODO DAM
- TIO.tui_ungetch(KEY_RESIZE); // TODO DAM
+
+ TUI.flush_input();
+ TUI.set_next_key(TUI.Keys.Resize);
while (true) {
if (is_terminal_too_small) {
@@ -1496,8 +1509,7 @@ main :: () {
}
reset_temporary_storage();
- //timeout(INPUT_TIMEOUT_MS); TODO DAM
- key := TIO.tui_getch(); // getch(); TODO DAM
+ key := TUI.get_key(INPUT_TIMEOUT_MS);
if key == #char "q" || key == #char "Q" break;
update_times(*database);
//timeout(INPUT_AWAIT_INF); TODO DAM
@@ -1518,10 +1530,11 @@ main :: () {
else ifx (selected_idx < 0) then 1
else (selected_idx % layout_tasks_rows) + NUM_HEADER_ROWS;
}
+
if key == {
// When getch() times out.
- case .READ_ERROR;
+ case TUI.Keys.None;
if (is_autosave_enabled && countdown_to_autosave > 0) {
countdown_to_autosave -= INPUT_TIMEOUT_MS;
if (countdown_to_autosave <= 0) {
@@ -1534,14 +1547,13 @@ main :: () {
}
// When terminal is resized.
- case KEY_RESIZE;
- TIO.tui_clear_screen();
+ case TUI.Keys.Resize;
+ TUI.clear_terminal();
//getmaxyx(stdscr, *size_y, *size_x);
- TIO.update_terminal_size(); // TODO DAM
- size_x = TIO.terminal_state.width;
- size_y = TIO.terminal_state.height;
+ _y, _x := TUI.get_terminal_size();
+ size_y = xx _y;
+ size_x = xx _x;
print("resize:%x%", size_x, size_y);
- asd := TIO.tui_getch();
is_terminal_too_small = size_x < 60 || size_y < 3;
update_layout();
layout = *layouts[ifx size_x > 100 then Layouts.NORMAL else Layouts.COMPACT];
@@ -1853,19 +1865,19 @@ main :: () {
case KEY_HOME;
select_task(db, 0);
- case KEY_UP;
+ case TUI.Keys.Up;
select_task_by_delta(db, -1);
- case KEY_PPAGE;
+ case TUI.Keys.PgUp;
select_task_by_delta(db, -layout_tasks_rows);
case KEY_END;
select_task(db, db.tasks.count-1);
- case KEY_DOWN;
+ case TUI.Keys.Down;
select_task_by_delta(db, 1);
- case KEY_NPAGE;
+ case TUI.Keys.PgDown;
select_task_by_delta(db, layout_tasks_rows);
}
}
@@ -1892,7 +1904,7 @@ main :: () {
//getch(); TODO DAM
}
- TIO.terminate(); // TODO DAM
+ TUI.stop();
exit(xx ifx error_saving then 1 else 0);
}