diff options
| author | dam <dam@gudinoff> | 2024-05-09 22:24:16 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2024-05-09 22:24:16 +0100 |
| commit | 18cd73bb1830fd49089eb82667ba6ae14606938c (patch) | |
| tree | 269ad4b6d5a72d95330a464dacf85a5b42c763f2 /ttt.jai | |
| parent | c0dc68c4672f53f2b9c60074bfb1eb10ab87d980 (diff) | |
| download | task-time-tracker-18cd73bb1830fd49089eb82667ba6ae14606938c.tar.zst task-time-tracker-18cd73bb1830fd49089eb82667ba6ae14606938c.zip | |
Renamed stuff to make TUI output builder purpose more clear.
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -204,6 +204,11 @@ count_digits :: (number: s64, base: s64 = 10) -> s64 { // Prints, on row y and column x, the time using 5 characters centered on space. // Returns the result of a call to mvprintw. print_time :: (y: int, x: int, time: s64, space: int) -> int { + + // Use TUI stubs so that callers may choose to use the tui_builder buffer. + print :: TUI.tui_print; + write_string :: TUI.tui_write_string; + TIME_CHARS :: 5; assert(space >= TIME_CHARS); @@ -217,7 +222,7 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int { print_padding :: (size: int) { assert(size >= 0, "Cannot print negative padding values. The procedure accepts signed values just for convenience."); while size > 0 { - TUI.tui_write_string(" "); + write_string(" "); size -= 1; } } @@ -226,19 +231,19 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int { if time < 0 { print_padding(left_padding); - TUI.tui_write_string(" - "); + write_string(" - "); print_padding(right_padding); return 0; } else if time == 0 { print_padding(left_padding); - TUI.tui_write_string(" 0 "); + write_string(" 0 "); print_padding(right_padding); return 0; } else if time < SECONDS_IN_MINUTE { print_padding(left_padding); - TUI.tui_print("%s ", FormatInt.{value = time, minimum_digits=3, padding=#char " "}); + print("%s ", FormatInt.{value = time, minimum_digits=3, padding=#char " "}); print_padding(right_padding); return 0; } @@ -246,7 +251,7 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int { hours := time / SECONDS_IN_HOUR; minutes := (time - (hours * SECONDS_IN_HOUR) ) / SECONDS_IN_MINUTE; print_padding(left_padding); - TUI.tui_print("%:%", FormatInt.{value = hours, minimum_digits=2}, FormatInt.{value = minutes, minimum_digits=2}); + print("%:%", FormatInt.{value = hours, minimum_digits=2}, FormatInt.{value = minutes, minimum_digits=2}); print_padding(right_padding); return 0; } @@ -257,7 +262,7 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int { ifx time >= #run mul_f64_s64(9.995, SECONDS_IN_DAY) then 1 else 2; print_padding(left_padding); - TUI.tui_print("%d", FormatFloat.{value = value, trailing_width=decimals, width=4}); + print("%d", FormatFloat.{value = value, trailing_width=decimals, width=4}); print_padding(right_padding); return 0; } @@ -268,13 +273,13 @@ print_time :: (y: int, x: int, time: s64, space: int) -> int { ifx time >= #run mul_f64_s64(9.995, SECONDS_IN_YEAR) then 1 else 2; print_padding(left_padding); - TUI.tui_print("%y", FormatFloat.{value = value, trailing_width=decimals, width=4}); + print("%y", FormatFloat.{value = value, trailing_width=decimals, width=4}); print_padding(right_padding); return 0; } else { print_padding(left_padding); - TUI.tui_write_string(" ∞ "); + write_string(" ∞ "); print_padding(right_padding); return 0; } @@ -907,10 +912,16 @@ draw_user_interface :: (db: *Database, layout: *Layout) { empty_line := talloc_string(size_x); memset(empty_line.data, #char " ", size_x); + /* TODO + It's not safe to use temporary memory here because the console resolution may increase and use more than what we have in temporary memory. + And temporary memory is configured at compile time. + We should dynamically allocate memory with some headroom and, at beggining of function... adjust it if necessary. + // init_string_builder(*buffer, 100000); // builder := buffer; + */ builder := String_Builder.{ allocator = temporary_allocator }; - TUI.using_buffer(*builder); + TUI.using_builder_as_output(*builder); adjust_first_day_of_week := int.[ (0 + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS, |
