diff options
| -rw-r--r-- | modules/TUI/module.jai | 110 | ||||
| -rw-r--r-- | modules/TUI/palette_24b.jai | 44 | ||||
| -rw-r--r-- | modules/TUI/palette_4b.jai | 19 | ||||
| -rw-r--r-- | modules/TUI/palette_8b.jai | 307 | ||||
| -rw-r--r-- | ttt.jai | 167 |
5 files changed, 514 insertions, 133 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 225b13e..21cd88a 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -1,3 +1,5 @@ +#module_parameters(COLOR_BIT_DEPTH := 24); + #if OS == { case .LINUX; #load "unix.jai"; @@ -103,84 +105,80 @@ Commands :: struct { QueryWindowSizeInChars :: "\e[18t"; // Emits the window size as: "ESC [ 8 <r> ; <c> t" Where <r> = row and <c> = column. TODO Does not work on windows. } -Palette_8b :: enum u8 { - BLACK :: 0; - MAROON :: 1; - GREEN :: 2; - OLIVE :: 3; - NAVY :: 4; - PURPLE :: 5; - TEAL :: 6; - SILVER :: 7; - GRAY :: 8; - RED :: 9; - LIME :: 10; - YELLOW :: 11; - BLUE :: 12; - MAGENTA :: 13; - CYAN :: 14; - WHITE :: 15; +#if COLOR_BIT_DEPTH == 4 { + #load "palette_4b.jai"; + + set_colors :: inline (foreground: Palette, background: Palette) { + print( + #run sprint("% %", Commands.SetGraphicsRendition, Commands.SetGraphicsRendition), + cast(u8)foreground + 30, cast(u8)background + 40); + } } +else #if COLOR_BIT_DEPTH == 8 { + #load "palette_8b.jai"; -Color_24b :: struct { - r: u8; - g: u8; - b: u8; + set_colors :: inline (foreground: Palette, background: Palette) { + print( + #run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"), + cast(u8)foreground, cast(u8)background); + } } +else { + #load "palette_24b.jai"; -// Fix color tables using this: https://devmemo.io/cheatsheets/terminal_escape_code/ - - -// TODO Maybe rename. -set_style_colors :: (foreground: Palette_8b, background: Palette_8b) { - print( - #run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"), - cast(u8)foreground, cast(u8)background); -} + Color_24b :: struct { + r: u8; + g: u8; + b: u8; + } -set_colors_24b :: (foreground_r: Color_24b, background: Color_24b) { - print( - #run sprint(Commands.SetGraphicsRendition, "38;2;%;%;%;48;2;%;%;%"), - foreground.r, foreground.g, foreground.b, - background.r, background.g, background.b); + set_colors :: inline (foreground: Color_24b, background: Color_24b) { + print( + #run sprint(Commands.SetGraphicsRendition, "38;2;%;%;%;48;2;%;%;%"), + foreground.r, foreground.g, foreground.b, + background.r, background.g, background.b); + } } -// set_colors_24b :: (foreground_r: u255) // TODO https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit +#add_context tui_style: Style; Style :: struct { - background: Palette_8b; - foreground: Palette_8b; + #if COLOR_BIT_DEPTH == 4 || COLOR_BIT_DEPTH == 8 { + background: Palette = .BLACK; + foreground: Palette = .WHITE; + } else { + background: Color_24b; + foreground: Color_24b; + } bold: bool; underline: bool; strike_through: bool; negative: bool; } -test :: () { - start(); - set_cursor_position(2, 2); - set_style_colors(.RED, .BLACK); - print(" RED \n"); - set_style_colors(.MAGENTA, .BLACK); - print(" MAGENTA \n"); - set_style_colors(.TEAL, .BLACK); - print(" TEAL \n"); - sleep_milliseconds(3000); - stop(); +set_font_style :: inline (bold: bool, underline: bool = false, strike_through: bool = false, negative: bool = false) { + print( + #run sprint(Commands.SetGraphicsRendition, "%;%;%;%"), + ifx bold then 1 else 22, + ifx underline then 4 else 24, + ifx strike_through then 9 else 29, + ifx negative then 7 else 27); } +set_style :: (style: Style) { + set_font_style(style.bold, style.underline, style.strike_through, style.negative); + set_colors(style.foreground, style.background); + context.tui_style = style; +} clear_style :: () { write_string(#run sprint(Commands.SetGraphicsRendition, "0")); } -set_style :: (bold: bool, underline: bool = false, strike_through: bool = false, negative: bool = false) { - print( - #run sprint(Commands.SetGraphicsRendition, "%;%;%;%"), - ifx bold then 1 else 22, - ifx underline then 4 else 24, - ifx strike_through then 9 else 29, - ifx negative then 7 else 27); +using_style :: (style: Style) #expand { + __style := context.tui_style; + set_style(style); + `defer set_style(__style); } // TODO Maybe make the OS_* procedures as inline?! diff --git a/modules/TUI/palette_24b.jai b/modules/TUI/palette_24b.jai new file mode 100644 index 0000000..7a263a0 --- /dev/null +++ b/modules/TUI/palette_24b.jai @@ -0,0 +1,44 @@ +// https://www.ditig.com/publications/256-colors-cheat-sheet +Palette :: struct { + BLACK :: Color_24b.{0x00, 0x00, 0x00}; + MAROON :: Color_24b.{0x80, 0x00, 0x00}; + GREEN :: Color_24b.{0x00, 0x80, 0x00}; + OLIVE :: Color_24b.{0x80, 0x80, 0x00}; + NAVY :: Color_24b.{0x00, 0x00, 0x80}; + PURPLE :: Color_24b.{0x80, 0x00, 0x80}; + TEAL :: Color_24b.{0x00, 0x80, 0x80}; + SILVER :: Color_24b.{0xC0, 0xC0, 0xC0}; + GRAY :: Color_24b.{0x80, 0x80, 0x80}; + RED :: Color_24b.{0xFF, 0x00, 0x00}; + LIME :: Color_24b.{0x00, 0xFF, 0x00}; + YELLOW :: Color_24b.{0xFF, 0xFF, 0x00}; + BLUE :: Color_24b.{0x00, 0x00, 0xFF}; + MAGENTA :: Color_24b.{0xFF, 0x00, 0xFF}; + CYAN :: Color_24b.{0x00, 0xFF, 0xFF}; + WHITE :: Color_24b.{0xFF, 0xFF, 0xFF}; + + GRAY_3 :: Color_24b.{0x08, 0x08, 0x08}; + GRAY_7 :: Color_24b.{0x12, 0x12, 0x12}; + GRAY_10 :: Color_24b.{0x1C, 0x1C, 0x1C}; + GRAY_14 :: Color_24b.{0x26, 0x26, 0x26}; + GRAY_18 :: Color_24b.{0x30, 0x30, 0x30}; + GRAY_22 :: Color_24b.{0x3A, 0x3A, 0x3A}; + GRAY_26 :: Color_24b.{0x44, 0x44, 0x44}; + GRAY_30 :: Color_24b.{0x4E, 0x4E, 0x4E}; + GRAY_34 :: Color_24b.{0x58, 0x58, 0x58}; + GRAY_37 :: Color_24b.{0x62, 0x62, 0x62}; + GRAY_40 :: Color_24b.{0x6C, 0x6C, 0x6C}; + GRAY_46 :: Color_24b.{0x76, 0x76, 0x76}; + GRAY_50 :: GRAY; + GRAY_54 :: Color_24b.{0x8A, 0x8A, 0x8A}; + GRAY_58 :: Color_24b.{0x94, 0x94, 0x94}; + GRAY_61 :: Color_24b.{0x9E, 0x9E, 0x9E}; + GRAY_65 :: Color_24b.{0xA8, 0xA8, 0xA8}; + GRAY_69 :: Color_24b.{0xB2, 0xB2, 0xB2}; + GRAY_73 :: Color_24b.{0xBC, 0xBC, 0xBC}; + GRAY_77 :: Color_24b.{0xC6, 0xC6, 0xC6}; + GRAY_81 :: Color_24b.{0xD0, 0xD0, 0xD0}; + GRAY_85 :: Color_24b.{0xDA, 0xDA, 0xDA}; + GRAY_89 :: Color_24b.{0xE4, 0xE4, 0xE4}; + GRAY_93 :: Color_24b.{0xEE, 0xEE, 0xEE}; +} diff --git a/modules/TUI/palette_4b.jai b/modules/TUI/palette_4b.jai new file mode 100644 index 0000000..b0317d2 --- /dev/null +++ b/modules/TUI/palette_4b.jai @@ -0,0 +1,19 @@ +// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit +Palette :: enum u8 { + BLACK :: 0; + MAROON :: 1; + GREEN :: 2; + OLIVE :: 3; + NAVY :: 4; + PURPLE :: 5; + TEAL :: 6; + SILVER :: 7; + GRAY :: 60; + RED :: 61; + LIME :: 62; + YELLOW :: 63; + BLUE :: 64; + MAGENTA :: 65; + CYAN :: 66; + WHITE :: 67; +} diff --git a/modules/TUI/palette_8b.jai b/modules/TUI/palette_8b.jai new file mode 100644 index 0000000..36a512f --- /dev/null +++ b/modules/TUI/palette_8b.jai @@ -0,0 +1,307 @@ +// https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit +Palette :: enum u8 { + BLACK :: 0; + MAROON :: 1; + GREEN :: 2; + OLIVE :: 3; + NAVY :: 4; + PURPLE :: 5; + TEAL :: 6; + SILVER :: 7; + GRAY :: 8; + RED :: 9; + LIME :: 10; + YELLOW :: 11; + BLUE :: 12; + MAGENTA :: 13; + CYAN :: 14; + WHITE :: 15; + + + x000000 :: 16; + x00005F :: 17; + x000087 :: 18; + x0000AF :: 19; + x0000D7 :: 20; + x0000FF :: 21; + + x005F00 :: 22; + x005F5F :: 23; + x005F87 :: 24; + x005FAF :: 25; + x005FD7 :: 26; + x005FFF :: 27; + + x008700 :: 28; + x00875F :: 29; + x008787 :: 30; + x0087AF :: 31; + x0087D7 :: 32; + x0087FF :: 33; + + x00AF00 :: 34; + x00AF5F :: 35; + x00AF87 :: 36; + x00AFAF :: 37; + x00AFD7 :: 38; + x00AFFF :: 39; + + x00D700 :: 40; + x00D75F :: 41; + x00D787 :: 42; + x00D7AF :: 43; + x00D7D7 :: 44; + x00D7FF :: 45; + + x00FF00 :: 46; + x00FF5F :: 47; + x00FF87 :: 48; + x00FFAF :: 49; + x00FFD7 :: 50; + x00FFFF :: 51; + + + x5F0000 :: 52; + x5F005F :: 53; + x5F0087 :: 54; + x5F00AF :: 55; + x5F00D7 :: 56; + x5F00FF :: 57; + + x5F5F00 :: 58; + x5F5F5F :: 59; + x5F5F87 :: 60; + x5F5FAF :: 61; + x5F5FD7 :: 62; + x5F5FFF :: 63; + + x5F8700 :: 64; + x5F875F :: 65; + x5F8787 :: 66; + x5F87AF :: 67; + x5F87D7 :: 68; + x5F87FF :: 69; + + x5FAF00 :: 70; + x5FAF5F :: 71; + x5FAF87 :: 72; + x5FAFAF :: 73; + x5FAFD7 :: 74; + x5FAFFF :: 75; + + x5FD700 :: 76; + x5FD75F :: 77; + x5FD787 :: 78; + x5FD7AF :: 79; + x5FD7D7 :: 80; + x5FD7FF :: 81; + + x5FFF00 :: 82; + x5FFF5F :: 83; + x5FFF87 :: 84; + x5FFFAF :: 85; + x5FFFD7 :: 86; + x5FFFFF :: 87; + + + x870000 :: 88; + x87005F :: 89; + x870087 :: 90; + x8700AF :: 91; + x8700D7 :: 92; + x8700FF :: 93; + + x875F00 :: 94; + x875F5F :: 95; + x875F87 :: 96; + x875FAF :: 97; + x875FD7 :: 98; + x875FFF :: 99; + + x878700 :: 100; + x87875F :: 101; + x878787 :: 102; + x8787AF :: 103; + x8787D7 :: 104; + x8787FF :: 105; + + x87AF00 :: 106; + x87AF5F :: 107; + x87AF87 :: 108; + x87AFAF :: 109; + x87AFD7 :: 110; + x87AFFF :: 111; + + x87D700 :: 112; + x87D75F :: 113; + x87D787 :: 114; + x87D7AF :: 115; + x87D7D7 :: 116; + x87D7FF :: 117; + + x87FF00 :: 118; + x87FF5F :: 119; + x87FF87 :: 120; + x87FFAF :: 121; + x87FFD7 :: 122; + x87FFFF :: 123; + + + xAF0000 :: 124; + xAF005F :: 125; + xAF0087 :: 126; + xAF00AF :: 127; + xAF00D7 :: 128; + xAF00FF :: 129; + + xAF5F00 :: 130; + xAF5F5F :: 131; + xAF5F87 :: 132; + xAF5FAF :: 133; + xAF5FD7 :: 134; + xAF5FFF :: 135; + + xAF8700 :: 136; + xAF875F :: 137; + xAF8787 :: 138; + xAF87AF :: 139; + xAF87D7 :: 140; + xAF87FF :: 141; + + xAFAF00 :: 142; + xAFAF5F :: 143; + xAFAF87 :: 144; + xAFAFAF :: 145; + xAFAFD7 :: 146; + xAFAFFF :: 147; + + xAFD700 :: 148; + xAFD75F :: 149; + xAFD787 :: 150; + xAFD7AF :: 151; + xAFD7D7 :: 152; + xAFD7FF :: 153; + + xAFFF00 :: 154; + xAFFF5F :: 155; + xAFFF87 :: 156; + xAFFFAF :: 157; + xAFFFD7 :: 158; + xAFFFFF :: 159; + + + xD70000 :: 160; + xD7005F :: 161; + xD70087 :: 162; + xD700AF :: 163; + xD700D7 :: 164; + xD700FF :: 165; + + xD75F00 :: 166; + xD75F5F :: 167; + xD75F87 :: 168; + xD75FAF :: 169; + xD75FD7 :: 170; + xD75FFF :: 171; + + xD78700 :: 172; + xD7875F :: 173; + xD78787 :: 174; + xD787AF :: 175; + xD787D7 :: 176; + xD787FF :: 177; + + xD7AF00 :: 178; + xD7AF5F :: 179; + xD7AF87 :: 180; + xD7AFAF :: 181; + xD7AFD7 :: 182; + xD7AFFF :: 183; + + xD7D700 :: 184; + xD7D75F :: 185; + xD7D787 :: 186; + xD7D7AF :: 187; + xD7D7D7 :: 188; + xD7D7FF :: 189; + + xD7FF00 :: 190; + xD7FF5F :: 191; + xD7FF87 :: 192; + xD7FFAF :: 193; + xD7FFD7 :: 194; + xD7FFFF :: 195; + + + xFF0000 :: 196; + xFF005F :: 197; + xFF0087 :: 198; + xFF00AF :: 199; + xFF00D7 :: 200; + xFF00FF :: 201; + + xFF5F00 :: 202; + xFF5F5F :: 203; + xFF5F87 :: 204; + xFF5FAF :: 205; + xFF5FD7 :: 206; + xFF5FFF :: 207; + + xFF8700 :: 208; + xFF875F :: 209; + xFF8787 :: 210; + xFF87AF :: 211; + xFF87D7 :: 212; + xFF87FF :: 213; + + xFFAF00 :: 214; + xFFAF5F :: 215; + xFFAF87 :: 216; + xFFAFAF :: 217; + xFFAFD7 :: 218; + xFFAFFF :: 219; + + xFFD700 :: 220; + xFFD75F :: 221; + xFFD787 :: 222; + xFFD7AF :: 223; + xFFD7D7 :: 224; + xFFD7FF :: 225; + + xFFFF00 :: 226; + xFFFF5F :: 227; + xFFFF87 :: 228; + xFFFFAF :: 229; + xFFFFD7 :: 230; + xFFFFFF :: 231; + + + // Grayscale + x080808 :: 232; + x121212 :: 233; + x1C1C1C :: 234; + x262626 :: 235; + x303030 :: 236; + x3A3A3A :: 237; + + x444444 :: 238; + x4E4E4E :: 239; + x585858 :: 240; + x636363 :: 241; + x6C6C6C :: 242; + x767676 :: 243; + + x808080 :: 244; + x8A8A8A :: 245; + x949494 :: 246; + x9E9E9E :: 247; + xA8A8A8 :: 248; + xB2B2B2 :: 249; + + xBCBCBC :: 250; + xC6C6C6 :: 251; + xD0D0D0 :: 252; + xDADADA :: 253; + xE4E4E4 :: 254; + xEEEEEE :: 255; +} @@ -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; |
