aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-07-18 01:40:20 +0100
committerdam <dam@gudinoff>2023-07-18 01:40:20 +0100
commit9d14c9ed9f0a1db804d2e7404807d00c66549687 (patch)
tree0ebceb576e12628b18a90a3ff3b16278183fc05e
parentdeaa914add9200fe66c09ea930c367ed190a46aa (diff)
downloadtask-time-tracker-9d14c9ed9f0a1db804d2e7404807d00c66549687.tar.zst
task-time-tracker-9d14c9ed9f0a1db804d2e7404807d00c66549687.zip
Cleaning up.
-rw-r--r--ttt.jai26
1 files changed, 13 insertions, 13 deletions
diff --git a/ttt.jai b/ttt.jai
index f3cc372..3f78ecd 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -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);
}