aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-11-15 02:18:43 +0000
committerdam <dam@gudinoff>2022-11-15 02:18:43 +0000
commit28eb0211471eda8e651aa8a7fffd48b611581dc1 (patch)
tree8b4aac7bafb145cecc889c7c83f99782565cf50b
parent6475865459debdd07df27d6a9a3b6679a6fad69d (diff)
downloadtask-time-tracker-28eb0211471eda8e651aa8a7fffd48b611581dc1.tar.zst
task-time-tracker-28eb0211471eda8e651aa8a7fffd48b611581dc1.zip
Validated draw_tui.
-rw-r--r--main.c29
-rw-r--r--readme.md3
2 files changed, 15 insertions, 17 deletions
diff --git a/main.c b/main.c
index 5ddbf08..69c0e78 100644
--- a/main.c
+++ b/main.c
@@ -245,7 +245,6 @@ task_st *get_active_task(database_st *db) {
if (db->active_task >= 0) {
task = db->tasks + db->active_task;
}
-
return task;
}
@@ -257,7 +256,6 @@ task_st *get_selected_task(database_st *db) {
if (db->selected_task >= 0) {
task = db->tasks + db->selected_task;
}
-
return task;
}
@@ -319,7 +317,6 @@ bool duplicate_task(database_st *db, task_st *task) {
// Add task time values to total times.
for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) {
-// db->total_times[idx] += task->times[idx]; TODO
db->total_times[idx] = add_int64(db->total_times[idx], new_task->times[idx]);
}
@@ -336,7 +333,6 @@ bool delete_task(database_st *db, task_st *task) {
// Remove task timer values from total timers.
for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) {
-// db->total_times[idx] -= task->times[idx]; TODO
db->total_times[idx] = sub_int64(db->total_times[idx], task->times[idx]);
}
@@ -670,7 +666,6 @@ bool import_from_csv(database_st *db, const char *path) {
fclose(file);
free(csv_buffer);
-
return true;
}
@@ -749,11 +744,13 @@ void set_active_task(database_st *db, task_st *task) {
#define L_DAYS_IDX 1
#define L_TOTAL_IDX 8
-#define THEME_A 1
-#define THEME_B 2
-#define THEME_C 3
-#define THEME_D 4
-#define THEME_E 5
+typedef enum { // TODO Improve theme names.
+ THEME_A = 1,
+ THEME_B,
+ THEME_C,
+ THEME_D,
+ THEME_E,
+} themes_et;
typedef enum {
L_NORMAL,
@@ -855,7 +852,7 @@ void update_layout() {
layout_tasks_rows = (size_y - NUM_HEADER_ROWS - NUM_FOOTER_ROWS);
// Calculate first column width: expands to fill the remaining space dynamically.
- for (layout_st *layout = layouts; layout <= &layouts[NUM_LAYOUTS-1]; layout++) {
+ for (layout_st *layout = layouts; layout <= &layouts[NUM_LAYOUTS - 1]; layout++) {
layout->columns[0].width = size_x - (NUM_COLUMNS - 1) - 2;
for (int idx = 1; idx < NUM_COLUMNS; idx++) {
layout->columns[0].width -= layout->columns[idx].width;
@@ -949,7 +946,7 @@ void draw_tui(database_st *db, layout_st *layout) {
int column_width;
// TODO This is some sort of pagination to allow scrolling through the tasks.
- // TODO How does this behaves when no task is selected?
+ // TODO How does this behaves when no task is selected? Well!
y = 0;
size_t idx_start = (db->selected_task / layout_tasks_rows) * layout_tasks_rows;
size_t idx_stop = idx_start + (layout_tasks_rows > db->count - idx_start ? db->count - idx_start : layout_tasks_rows);
@@ -1004,15 +1001,15 @@ void draw_tui(database_st *db, layout_st *layout) {
///////////////////////////////////////////////////////////////////////////
// Draw selected/total tasks.
- snprintf(string_buffer, string_buffer_size, " %td/%zd ", db->selected_task+1, db->count);
+ snprintf(string_buffer, string_buffer_size, " %td/%zd ", db->selected_task + 1, db->count);
if (strlen(string_buffer) > layout->columns[L_TITLE_IDX].width) {
- snprintf(string_buffer, string_buffer_size, "%td", db->selected_task+1);
+ snprintf(string_buffer, string_buffer_size, "%td", db->selected_task + 1);
}
- mvaddstr(size_y-1, 1, string_buffer);
+ mvaddstr(size_y - 1, 1, string_buffer);
///////////////////////////////////////////////////////////////////////////
// Draw daily totals.
- y = size_y-1;
+ y = size_y - 1;
x = 0 + 1 + layout->columns[L_TITLE_IDX].width;
total_time = 0;
for (int raw_idx = 0; raw_idx < NUM_WEEK_DAYS; raw_idx++) {
diff --git a/readme.md b/readme.md
index b241a57..5c76d63 100644
--- a/readme.md
+++ b/readme.md
@@ -67,7 +67,8 @@ Task Time Tracker
- [x] Wrap malloc (and maybe others) in a function with error checking;
- [x] Move database actions into functions;
- [x] Fix bug: archiving/unarchiving task introduces " ," at end of name and increases the number of spaces before comma;
-- [ ] Check if draw_tui may be simplified by drawing entire lines of tasks at once and draw columns separators after;
+- [x] Check if draw_tui may be simplified by drawing entire lines of tasks at once and draw columns separators after;
+ - By having each column-print job decoulpled, we avoid havint to measure and compensate lengths of UTF8 strings;
- [ ] Review all code for bugs related to auto-cast on ptrdiff_t/size_t (signed/unsigned);
- [ ] Try to fix flickering of ncurses;
- [ ] Go over all `TODO` items;