aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai167
1 files changed, 90 insertions, 77 deletions
diff --git a/ttt.jai b/ttt.jai
index 35a4bc2..a07502f 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -25,7 +25,7 @@
#import "File_Utilities";
#import "String";
#import "Integer_Saturating_Arithmetic";
-TUI :: #import "TUI";
+TUI :: #import "TUI"(COLOR_BIT_DEPTH=8);
// TODO List:
@@ -84,13 +84,39 @@ size_y : int;
pos_x : int;
pos_y : int;
-Styles :: enum s16 {
- SELECTED :: 1;
- SELECTED_INVERTED;
- ACTIVE;
- ACTIVE_SELECTED;
- ERROR;
-}
+style_default := TUI.Style.{
+ background = TUI.Palette.BLACK,
+ foreground = TUI.Palette.WHITE,
+};
+
+style_selected := TUI.Style.{
+ background = TUI.Palette.CYAN,
+ foreground = TUI.Palette.BLACK,
+};
+
+style_selected_inverted := TUI.Style.{
+ background = TUI.Palette.BLACK,
+ foreground = TUI.Palette.CYAN,
+ bold = true,
+};
+
+style_active := TUI.Style.{
+ background = TUI.Palette.BLACK,
+ foreground = TUI.Palette.BLUE,
+ bold = true,
+};
+
+style_active_selected := TUI.Style.{
+ background = TUI.Palette.NAVY,
+ foreground = TUI.Palette.WHITE,
+ bold = true,
+};
+
+style_error := TUI.Style.{
+ background = TUI.Palette.BLACK,
+ foreground = TUI.Palette.RED,
+ bold = true,
+};
Layouts :: enum u8 {
NORMAL;
@@ -157,7 +183,7 @@ trigger_autosave :: () {
show_processing :: () {
TUI.set_cursor_position(1, 1);
- // TODO Maybe add some color?
+ TUI.using_style(style_active);
write_strings(TUI.Commands.DrawingMode, TUI.Drawings.Diamond, TUI.Commands.TextMode);
}
@@ -915,22 +941,7 @@ initialize_tui :: () {
}
}
- // TODO DAM
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
- // curs_set(0); // Set cursor invisible. TODO DAM
- // noecho(); // Disable echoing input characters. TODO DAM
-
- // Initialize pairs of colors.
- //start_color(); TODO DAM
- //use_default_colors(); // Using default (-1) instead of COLOR_BLACK. TODO DAM
- //init_pair(xx Styles.SELECTED, COLOR_BLACK, COLOR_CYAN); TODO DAM
- //init_pair(xx Styles.SELECTED_INVERTED, COLOR_CYAN, -1); TODO DAM
- //init_pair(xx Styles.ACTIVE, COLOR_BLUE, -1); TODO DAM
- //init_pair(xx Styles.ACTIVE_SELECTED, COLOR_WHITE, COLOR_BLUE); TODO DAM
- //init_pair(xx Styles.ERROR, COLOR_RED, -1); TODO DAM
}
update_layout :: () {
@@ -1015,10 +1026,13 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Apply theme.
if (idx == now_week_day && active_task != null) {
- // attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD); TODO DAM
+ TUI.set_style(style_active);
}
else if (idx == now_week_day) {
- // attron(COLOR_PAIR(xx Styles.SELECTED_INVERTED) | A_BOLD); TODO DAM
+ TUI.set_style(style_selected_inverted);
+ }
+ else {
+ TUI.set_style(style_default);
}
col = *layout.columns[L_DAYS_IDX + idx];
@@ -1026,9 +1040,6 @@ draw_tui :: (db: *Database, layout: *Layout) {
TUI.set_cursor_position(y, x + col.alignment_offset);
write_string(col.header);
x += col.width;
-
- // Reset theme.
- //attrset(A_NORMAL); TODO DAM
}
// Headers : total
@@ -1058,18 +1069,13 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Apply theme.
if (task == active_task && task == selected_task) {
- // attron(COLOR_PAIR(xx Styles.ACTIVE_SELECTED) | A_BOLD); TODO DAM
- TUI.set_style_colors(.RED, 6); // TODO TESTING COLORS
- TUI.set_style(true, true, true, false);
+ TUI.set_style(style_active_selected);
}
else if (task == selected_task) {
- // attron(COLOR_PAIR(xx Styles.SELECTED)); TODO DAM
- TUI.set_style_colors(4, 6); // TODO TESTING COLORS
+ TUI.set_style(style_selected);
}
else if (task == active_task) {
- TUI.set_style_colors(.RED, 6); // TODO TESTING COLORS
- TUI.set_style(false, false, false, true); // TODO TESTING STYLE
- // attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD); TODO DAM
+ TUI.set_style(style_active);
}
// Task title.
@@ -1136,19 +1142,19 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Apply theme.
if (idx == now_week_day && active_task != null) {
- // attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD); TODO DAM
+ TUI.set_style(style_active);
}
else if (idx == now_week_day) {
- // attron(COLOR_PAIR(xx Styles.SELECTED_INVERTED) | A_BOLD); TODO DAM
+ TUI.set_style(style_selected_inverted);
+ }
+ else {
+ TUI.set_style(style_default);
}
column_width = layout.columns[L_DAYS_IDX + idx].width;
total_time = add(total_time, daily_total);
print_time(y, x, daily_total, column_width);
x += column_width;
-
- // Reset theme.
- //attrset(A_NORMAL); TODO DAM
}
x += 1;
print_time(y, x, total_time, layout.columns[L_TOTAL_IDX].width);
@@ -1164,9 +1170,7 @@ free_memory :: () {
//reset_temporary_storage();
}
-read_input_string :: (row: int, column: int, style: s32, input_limit: int, padding: int = 0) -> value: string, success: bool {
-
- // TODO We still need to apply the style.
+read_input_string :: (row: int, column: 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)?
@@ -1188,7 +1192,7 @@ read_input_string :: (row: int, column: int, style: s32, input_limit: int, paddi
}
// Returns success.
-read_input_int :: (row: int, style: s32, message: string) -> value: int, success: bool {
+read_input_int :: (row: int, message: string) -> value: int, success: bool {
// attron(xx style); TODO DAM
//move(xx row, 1); TODO DAM
//addch(ACS_CKBOARD); TODO DAM
@@ -1198,14 +1202,14 @@ read_input_int :: (row: int, style: s32, message: string) -> value: int, success
// Get line number.
input_pos_x := 1;//getcurx(stdscr); TODO DAM
input_width := size_x - input_pos_x;
- str := read_input_string(row, input_pos_x, style, input_width);
+ str := read_input_string(row, input_pos_x, 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, style: int, message: string) -> TUI.Key {
+prompt_user_key :: (row: int, message: string) -> TUI.Key {
/*
assert(message.data != null, ASSERT_NOT_NULL, "message");
attron(xx style);
@@ -1236,10 +1240,6 @@ prompt_user_key :: (row: int, style: int, message: string) -> TUI.Key {
main :: () {
- TUI.test();
- exit(0);
-
-
// -- -- -- Testing TUI -- START
perform_test := false;
@@ -1656,9 +1656,14 @@ main :: () {
db := *database;
layout := *layouts[Layouts.COMPACT];
+ action_style: TUI.Style;
+
+
TUI.flush_input();
TUI.set_next_key(TUI.Keys.Resize);
while (true) {
+
+ TUI.set_style(style_default);
if (is_terminal_too_small) {
INVALID_WINDOW_MESSAGE :: "Terminal is too small: minimum 60x3.";
@@ -1679,18 +1684,14 @@ main :: () {
// TODO WIP Remove `selected_task` and `active_task` and helper functions.
selected_task := get_selected_task(db);
active_task := get_active_task(db);
- action_style: s32;
- error_style: s32;
selected_task_row: int;
{ // TODO Recheck this code.
using db;
- action_style = A_BOLD | COLOR_PAIR(xx
- ifx selected_idx == active_idx && selected_idx != -1 then Styles.ACTIVE
- else Styles.SELECTED_INVERTED);
- error_style = A_BOLD | COLOR_PAIR(xx Styles.ERROR);
- selected_task_row = ifx is_terminal_too_small then 0
- else ifx (selected_idx < 0) then 1
- else (selected_idx % layout_tasks_rows) + NUM_HEADER_ROWS + 1;
+ action_style = ifx selected_idx == active_idx && selected_idx != -1 then style_active else style_selected_inverted;
+
+ selected_task_row = ifx is_terminal_too_small then 0
+ else ifx (selected_idx < 0) then 1
+ else (selected_idx % layout_tasks_rows) + NUM_HEADER_ROWS + 1;
}
if key == {
@@ -1736,7 +1737,8 @@ main :: () {
case #char "n"; #through;
case #char "N";
if is_database_full(db) {
- prompt_user_key(selected_task_row, error_style, "Unable to create task: database is full.");
+ TUI.using_style(style_error);
+ prompt_user_key(selected_task_row, "Unable to create task: database is full.");
continue;
}
@@ -1762,7 +1764,8 @@ main :: () {
// Change task name.
// TODO WIPWIPWIP
- input := read_input_string(selected_task_row, 1, action_style, Task.name.count, size_x - 2 - Task.name.count);
+ TUI.using_style(action_style);
+ input := read_input_string(selected_task_row, 1, 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);
@@ -1773,16 +1776,18 @@ main :: () {
// Reset task timers.
case TUI.Keys.Backspace;
if (selected_task == null) continue;
-
- if (prompt_user_key(selected_task_row, action_style, "Press enter to reset task.") == TUI.Keys.Enter) {
+
+ TUI.using_style(action_style);
+ if (prompt_user_key(selected_task_row, "Press enter to reset task.") == TUI.Keys.Enter) {
reset_task_times(db, db.selected_idx);
trigger_autosave();
}
case TUI.Keys.Delete;
if (selected_task == null || selected_task == active_task) continue;
-
- if (prompt_user_key(selected_task_row, action_style, "Press enter to delete task.") == TUI.Keys.Enter) {
+
+ TUI.using_style(action_style);
+ if (prompt_user_key(selected_task_row, "Press enter to delete task.") == TUI.Keys.Enter) {
delete_task(db, db.selected_idx);
trigger_autosave();
}
@@ -1808,7 +1813,8 @@ main :: () {
input_pos_x += 1;
// Get input string.
- input := read_input_string(selected_task_row, input_pos_x, action_style, input_width); // TODO Temp stringzes.
+ TUI.using_style(action_style);
+ input := read_input_string(selected_task_row, input_pos_x, input_width); // TODO Temp stringzes.
// Abort if input if empty.
if is_empty_string(input) continue;
@@ -1850,8 +1856,9 @@ main :: () {
case #char "m"; #through;
case #char "M";
if selected_task == null continue;
-
- value, success := read_input_int(selected_task_row, action_style, " Move to: ");
+
+ TUI.using_style(action_style);
+ value, success := read_input_int(selected_task_row, " Move to: ");
if success == false continue;
move_task(db, db.selected_idx, value-1); // -1 to adjust for zero based index
trigger_autosave();
@@ -1860,8 +1867,9 @@ main :: () {
case #char "g"; #through;
case #char "G";
if selected_task == null continue;
-
- value, success := read_input_int(selected_task_row, action_style, " Go to: ");
+
+ TUI.using_style(action_style);
+ value, success := read_input_int(selected_task_row, " Go to: ");
if success == false continue;
target_index := clamp(value, 1, MAX_DATABASE_TASKS) - 1;
select_task(db, target_index);
@@ -1872,7 +1880,8 @@ main :: () {
if selected_task == null continue;
if is_database_full(db) {
- prompt_user_key(selected_task_row, error_style, "Unable to duplicate task: database is full.");
+ TUI.using_style(style_error);
+ prompt_user_key(selected_task_row, "Unable to duplicate task: database is full.");
continue;
}
@@ -1938,7 +1947,8 @@ main :: () {
if (db != *archive || selected_task == null) continue;
if is_database_full(*database) {
- prompt_user_key(selected_task_row, error_style, "Unable to restore task: database is full.");
+ TUI.using_style(style_error);
+ prompt_user_key(selected_task_row, "Unable to restore task: database is full.");
continue;
}
@@ -1953,7 +1963,8 @@ main :: () {
case #char "s"; #through;
case #char "S";
// TODO The initial part should only decide what's the sorting procedure... then we would would all in a single place.
- sort_by := prompt_user_key(selected_task_row, action_style, "Sort by (n) name, (1..7) day, or (t) total time.");
+ TUI.using_style(action_style);
+ sort_by := prompt_user_key(selected_task_row, "Sort by (n) name, (1..7) day, or (t) total time.");
show_processing();
sort_procedure: (a: Task, b: Task) -> s64;
@@ -2001,7 +2012,8 @@ main :: () {
case #char "w"; #through;
case #char "W";
if (db != *database || db.tasks.count <= 0) continue;
- if (prompt_user_key(selected_task_row, action_style, "Press enter to archive duplicates and reset all.") != TUI.Keys.Enter) continue;
+ TUI.using_style(action_style);
+ if (prompt_user_key(selected_task_row, "Press enter to archive duplicates and reset all.") != TUI.Keys.Enter) continue;
show_processing();
for db.tasks {
@@ -2016,7 +2028,8 @@ main :: () {
case #char "c"; #through;
case #char "C";
if (db.tasks.count <= 0) continue;
- if (prompt_user_key(selected_task_row, action_style, "Press enter to coalesce similar tasks.") != TUI.Keys.Enter) continue;
+ TUI.using_style(action_style);
+ if (prompt_user_key(selected_task_row, "Press enter to coalesce similar tasks.") != TUI.Keys.Enter) continue;
show_processing();
head_idx := 0;