aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-04-05 18:29:31 +0100
committerdam <dam@gudinoff>2023-04-05 18:29:31 +0100
commita1939b2707fea269bf6ba933b9dee60996aa6bc2 (patch)
treed37e62fb09aad0ad1dd3bb76cf952970947b23f8
parent78dc3662e80c63775ee61cfa0cb7cc74fa76bd98 (diff)
downloadtask-time-tracker-a1939b2707fea269bf6ba933b9dee60996aa6bc2.tar.zst
task-time-tracker-a1939b2707fea269bf6ba933b9dee60996aa6bc2.zip
Fixed variadic arguments on mvprintw binding.
-rw-r--r--curses.jai2
-rw-r--r--ttt.jai46
2 files changed, 24 insertions, 24 deletions
diff --git a/curses.jai b/curses.jai
index 87fb1dc..f8715c0 100644
--- a/curses.jai
+++ b/curses.jai
@@ -97,7 +97,7 @@ attron :: (attrs: s32) -> s32 #foreign ncurses
erase :: () -> s32 #foreign ncurses;
curs_set :: (visibility: s32) -> s32 #foreign ncurses;
mvaddstr :: (y: s32, x: s32, str: *u8) -> s32 #foreign ncurses;
-mvprintw :: (y: s32, x: s32, fmt: *u8, ...) -> s32 #foreign ncurses;
+mvprintw :: (y: s32, x: s32, fmt: *u8, args: ..Any) -> s32 #foreign ncurses;
noecho :: () -> s32 #foreign ncurses;
box :: (win: *WINDOW, verch: u8, horch: u8) -> s32 #foreign ncurses;
init_pair :: (pair: s16, f: s16, b: s16) -> s32 #foreign ncurses;
diff --git a/ttt.jai b/ttt.jai
index 9a5f26a..a5397ed 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -239,15 +239,16 @@ replace_char :: (str: string, find: u8, replace: u8) -> string {
// TODO Use modules/String/module.jai:replace_chars
return "";
}
-/*
+
// Prints, on row y and column x, the time using 5 characters centered on space.
// Returns the result of a call to mvprintw.
-int mvprintw_time(int y, int x, intmax_t time, int space) {
- const int TIME_CHARS = 5;
+mvprintw_time :: (y: s32, x: s32, time: s64, space: s32) -> int {
+ return 0; // TODO NOT WORKING
+ TIME_CHARS :: 5;
assert(space >= TIME_CHARS);
- int left_padding = (space - TIME_CHARS) / 2;
- int right_padding = space - TIME_CHARS - left_padding;
+ left_padding := (space - TIME_CHARS) / 2;
+ right_padding := space - TIME_CHARS - left_padding;
if (time < 0) {
return mvprintw(y, x, "%*s - %*s", left_padding, "", right_padding, "");
@@ -258,24 +259,24 @@ int mvprintw_time(int y, int x, intmax_t time, int space) {
else if (time < SECONDS_IN_MINUTE) {
return mvprintw(y, x, "%*s%3jds %*s", left_padding, "", time, right_padding, "");
}
- else if (time < (intmax_t)100 * SECONDS_IN_HOUR) {
- intmax_t hours = (double)time / (double)SECONDS_IN_HOUR;
- intmax_t minutes = (time - (hours * SECONDS_IN_HOUR) ) / SECONDS_IN_MINUTE;
+ else if (time < 100 * SECONDS_IN_HOUR) {
+ hours := cast(float64)time / cast(float64)SECONDS_IN_HOUR;
+ minutes := (time - (hours * SECONDS_IN_HOUR) ) / SECONDS_IN_MINUTE;
return mvprintw(y, x, "%*s%02jd:%02jd%*s", left_padding, "", hours, minutes, right_padding, "");
}
- else if (time < (intmax_t)(9999.5 * SECONDS_IN_DAY)) {
- double value = (double)time / (double)SECONDS_IN_DAY;
- int decimals =
- time >= 99.95 * SECONDS_IN_DAY ? 0 :
- time >= 9.995 * SECONDS_IN_DAY ? 1 :
+ else if (time < xx (9999.5 * SECONDS_IN_DAY)) {
+ value := cast(float64)time / cast(float64)SECONDS_IN_DAY;
+ decimals :=
+ ifx time >= xx 99.95 * SECONDS_IN_DAY then 0 else
+ ifx time >= xx 9.995 * SECONDS_IN_DAY then 1 else
2;
return mvprintw(y, x, "%*s%4.*fd%*s", left_padding, "", decimals, value, right_padding, "");
}
- else if (time < (intmax_t)(9999.5 * SECONDS_IN_YEAR)) {
- double value = (double)time / (double)SECONDS_IN_YEAR;
- int decimals =
- time >= 99.95 * SECONDS_IN_YEAR ? 0 :
- time >= 9.995 * SECONDS_IN_YEAR ? 1 :
+ else if (time < xx (9999.5 * SECONDS_IN_YEAR)) {
+ value := cast(float64)time / cast(float64)SECONDS_IN_YEAR;
+ decimals :=
+ ifx time >= xx 99.95 * SECONDS_IN_YEAR then 0 else
+ ifx time >= xx 9.995 * SECONDS_IN_YEAR then 1 else
2;
return mvprintw(y, x, "%*s%4.*fy%*s", left_padding, "", decimals, value, right_padding, "");
}
@@ -283,7 +284,6 @@ int mvprintw_time(int y, int x, intmax_t time, int space) {
return mvprintw(y, x, "%*s ∞ %*s", left_padding, "", right_padding, "");
}
}
-*/
add_int64 :: (x :s64, y: s64) -> s64 {
return
@@ -1131,7 +1131,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
idx_start := (db.selected_idx / layout_tasks_rows) * layout_tasks_rows;
// Display up to rows allowed by the layout, or less if reached end of database.
idx_stop := idx_start + (ifx layout_tasks_rows > db.tasks.count - idx_start then db.tasks.count - idx_start else layout_tasks_rows);
- for idx: idx_start..idx_stop {
+ for idx: idx_start..idx_stop-1 {
//for (size_t idx = idx_start; idx < idx_stop; idx++) {
task := *db.tasks[idx];
y += 1;
@@ -1151,7 +1151,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Task title.
x += 1;
column_width = layout.columns[L_TITLE_IDX].width;
- mvprintw(y, x, "%-*.*s", column_width, column_width, task.name);
+ mvprintw(xx y, xx x, "%-*.*s", column_width, column_width, task.name);
x += column_width;
// Task times.
@@ -1165,13 +1165,13 @@ draw_tui :: (db: *Database, layout: *Layout) {
column_width = layout.columns[L_DAYS_IDX + day_idx].width;
task_stime := task.times[day_idx];
total_time = add_int64(total_time, task_stime);
- mvprintw_time(xx y, xx x, task_stime, column_width);
+ mvprintw_time(xx y, xx x, task_stime, xx column_width);
x += column_width;
}
// Task total.
x += 1;
- mvprintw_time(xx y, xx x, total_time, layout.columns[L_TOTAL_IDX].width);
+ mvprintw_time(xx y, xx x, total_time, xx layout.columns[L_TOTAL_IDX].width);
// Reset theme.
attrset(A_NORMAL);