diff options
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -180,14 +180,16 @@ Text_Encoding :: enum u8 #specified { UTF8 :: 2; } -// TODO Provide good description. -number_size :: (number: s64, base: s64 = 10) -> s64 { +// Count digits required to represent number on base. Sign is discarded. +count_digits :: (number: s64, base: s64 = 10) -> s64 { if number == 0 return 1; - return cast(s64)floor(log(cast(float64)abs(number))/log(cast(float64)abs(base))) + 1; // TODO So many casts. + return cast(s64) floor( log(cast(float64)abs(number)) / log(cast(float64)abs(base)) ) + 1; } -// WIP TODO Ues compiler time code to see the auto bake being used... just for fun, once! :D -truncate_string :: (str: string, length: s64, $encoding: Text_Encoding = .UTF8) -> length: s64 #no_abc { // TODO Should I use #no_abc ? +// Truncates the string to the length provided or shorter, in case of UTF8 strings that require so. +// Truncation is done by zeroing the tail of the string in place. +// Returns length of truncated string. +truncate_string :: (str: string, length: s64, $encoding: Text_Encoding = .UTF8) -> length: s64 { assert(str.data != null, ASSERT_NOT_NULL, "str"); assert(str.count >= length, "'str.count' should be equal or greater to 'length'."); @@ -214,7 +216,7 @@ truncate_string :: (str: string, length: s64, $encoding: Text_Encoding = .UTF8) && !(continuation_bytes == 2 && (data[idx - 1] & 0xF0) == 0xE0) && !(continuation_bytes == 3 && (data[idx - 1] & 0xF8) == 0xF0) ) { - length -= (continuation_bytes + 1); // Remove '+ 1' start byte. + length -= (continuation_bytes + 1); // Remove start byte, ence '+ 1'. } } @@ -285,9 +287,8 @@ mvprintw_time :: (y: s32, x: s32, time: s64, space: s32) -> int { return mvprintw(y, x, "%*s%4.*fy%*s", left_padding, "", decimals, value, right_padding, ""); } else { - // TODO Solve unicode emoji gone wild. - //return mvprintw(y, x, "%*s ∞ %*s", left_padding, "", right_padding, ""); - //return mvprintw(y, x, "%*s \xE2\x99\xBE %*s", left_padding, "", right_padding, ""); + // TODO Set back the unicode emoji once ncurses has been replaced. + // return mvprintw(y, x, "%*s ∞ %*s", left_padding, "", right_padding, ""); return mvprintw(y, x, "%*s inf %*s", left_padding, "", right_padding, ""); } } @@ -352,8 +353,7 @@ delete_task :: (using db: *Database, index: s64) -> bool { // TODO Maybe use `us get_msb :: (value: s64) -> msb: s64, found: bool { result: s64 = ---; #asm { - mov val: gpr, value; - bsr result, val; + bsr result, value; } return result * xx cast(bool)value, xx value; // If value is zero: return `0, false`. } @@ -878,7 +878,7 @@ initialize_tui :: () { } // TODO - //setlocale(LC_ALL, "C.UTF-8"); // Sets locale for C library functions; Allows usage of UTF-8. + // setlocale(LC_ALL, "C.UTF-8"); // Sets locale for C library functions; Allows usage of UTF-8. stdscr = initscr(); // Start curses mode. cbreak(); // Line buffering disabled; pass on everty thing to me. keypad(stdscr, true); // I need those nifty F1..F12. @@ -1047,7 +1047,7 @@ draw_tui :: (db: *Database, layout: *Layout) { /////////////////////////////////////////////////////////////////////////// // Draw selected/total tasks. - size := 1 + number_size(db.selected_idx + 1) + 1 + number_size(db.tasks.count) + 1; // " XXX/YYY " + size := 1 + count_digits(db.selected_idx + 1) + 1 + count_digits(db.tasks.count) + 1; // " XXX/YYY " if (size <= layout.columns[L_TITLE_IDX].width) { mvprintw(size_y - 1, 1, " %td/%zd ", db.selected_idx + 1, db.tasks.count); } |
