aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c41
-rw-r--r--readme.md6
2 files changed, 28 insertions, 19 deletions
diff --git a/main.c b/main.c
index b1c44af..1cdc9ad 100644
--- a/main.c
+++ b/main.c
@@ -83,7 +83,7 @@ char *replace_char(char *string, char find, char replace) {
return string;
}
-char *format_time(intmax_t time, char* string, int length) {
+char *format_time(char* string, intmax_t time, int length) {
int left_padding = (length - 5) / 2;
int right_padding = length - 5 - left_padding;
@@ -420,16 +420,16 @@ bool import_from_csv(database_t *db, const char *path_name) {
fscanf(file, "%*[^\n]\n");
// Parse CSV file.
- char *line_buffer = NULL;
- size_t line_buffer_size = 0;
- while(getline(&line_buffer, &line_buffer_size, file) != -1) { // Check if reached EOF.
+ char *csv_buffer = NULL;
+ size_t csv_buffer_size = 0;
+ while(getline(&csv_buffer, &csv_buffer_size, file) != -1) { // Check if reached EOF.
// Find task name string limits.
- char *name_delimiter = strchr(line_buffer, ',');
+ char *name_delimiter = strchr(csv_buffer, ',');
if (name_delimiter == NULL) {
continue;
}
- size_t name_length = (name_delimiter - line_buffer) + 1;
+ size_t name_length = (name_delimiter - csv_buffer) + 1;
if (name_length > MAX_TASK_NAME) {
name_length = MAX_TASK_NAME;
}
@@ -439,7 +439,7 @@ bool import_from_csv(database_t *db, const char *path_name) {
create_task(db, &task);
// Import task name.
- memcpy(task->name, line_buffer, name_length);
+ memcpy(task->name, csv_buffer, name_length);
truncate_string_utf8(task->name, name_length);
// Parse task times.
@@ -453,8 +453,8 @@ bool import_from_csv(database_t *db, const char *path_name) {
&task->times[5],
&task->times[6]
) != 7) {
- replace_char(line_buffer, '\n', ' ');
- fprintf(stderr, "Discarding invalid line '%s' and continuing.\n", line_buffer);
+ replace_char(csv_buffer, '\n', ' ');
+ fprintf(stderr, "Discarding invalid line '%s' and continuing.\n", csv_buffer);
delete_task(db, task);
continue;
}
@@ -467,7 +467,7 @@ bool import_from_csv(database_t *db, const char *path_name) {
}
fclose(file);
- free(line_buffer);
+ free(csv_buffer);
return true;
}
@@ -851,7 +851,7 @@ void draw_tui(database_t *db, layout_t *layout) {
int column_width = layout->column_widths[L_DAYS_IDX + day_idx];
int64_t task_time = task->times[day_idx];
total_time = add_time(total_time, task_time);
- format_time(task_time, line_buffer, column_width);
+ format_time(line_buffer, task_time, column_width);
mvaddstr(y, x, line_buffer);
x += column_width;
}
@@ -859,7 +859,7 @@ void draw_tui(database_t *db, layout_t *layout) {
// Task total.
x++;
column_width = layout->column_widths[L_TOTAL_IDX]; // TODO
- format_time(total_time, line_buffer, column_width);
+ format_time(line_buffer, total_time, column_width);
mvaddstr(y, x, line_buffer);
// Reset theme.
@@ -886,13 +886,13 @@ void draw_tui(database_t *db, layout_t *layout) {
int64_t daily_total = db->total_times[day_idx];
column_width = layout->column_widths[day_idx + L_DAYS_IDX];
total_time = add_time(total_time, daily_total);
- format_time(daily_total, line_buffer, column_width);
+ format_time(line_buffer, daily_total, column_width);
mvaddstr(y, x, line_buffer);
x += column_width;
}
x++;
column_width = layout->column_widths[L_TOTAL_IDX];
- format_time(total_time, line_buffer, column_width);
+ format_time(line_buffer, total_time, column_width);
mvaddstr(y, x, line_buffer);
x += column_width;
}
@@ -1059,13 +1059,24 @@ int main(int argc, char *argv[]) {
}
// rename stuff
int row = db->selected_task + 1;
+ attron(COLOR_PAIR(selected_task == active_task ? THEME_E : THEME_D));
+ attron(A_BOLD);
mvaddch(row, 0, ACS_DIAMOND);
clrtoeol();
mvaddch(row, size_x-1, ACS_VLINE);
curs_set(1);
// TODO Make cursor blink.
- mvgetnstr(row, 1, selected_task->name, MAX_TASK_NAME-1);
+// mvgetnstr(row, 1, selected_task->name, MAX_TASK_NAME-1);
+ static char input[MAX_TASK_NAME];
+ mvgetnstr(row, 1, input, MAX_TASK_NAME-1); // TODO We are not sure the max task name is lower than the line_buffer size. Maybe the line_buffer should have a lower limit?
+ WIP Maybe guarantee that line_buffer is bigger than MAX_TASK_NAME and size_x?
+ input[MAX_TASK_NAME-1] = '\0';
+ truncate_string_utf8(input, MAX_TASK_NAME-1);
+ if (strlen(input) > 0) {
+ strcpy(selected_task->name, input);
+ }
curs_set(0);
+ attrset(A_NORMAL);
break;
}
diff --git a/readme.md b/readme.md
index 24f3f41..4ca6c10 100644
--- a/readme.md
+++ b/readme.md
@@ -28,12 +28,13 @@ Task Time Tracker
- [x] Status of task will allow to keep counting time even when the process gets terminated forcefully;
- [x] Review code: char !uint8_t;
- [x] Make sure that only one task is running at each time;
+- [x] Mouse selection is broken due to entire TUI update: No, it was fixed by using `erase()` on the `draw_tui` instead of `clear()`;
+- [ ] Allow to cancel a rename_task operation.
- [ ] Improve total_times:
- Create function to recalculate them. Shouldn't take so long, right?
- Decide when this will run.
- Check for overflow/underflow when adding/subtracting times;
- Only recalculate when we're potentially exiting a saturation point;
-- [ ] Allow to cancel a rename_task operation.
- [ ] Cleanup `draw_tui`:
- Selected and active tasks should be drawn after everything else.
- Try printing each row;
@@ -41,9 +42,6 @@ Task Time Tracker
- Allow to repaint just certain parts of the TUI; this should allow to call `draw_tui` with a flag saying which parts need to be drawn;
- [ ] Confirm delete_task operation.
- [ ] Implement logs as described above.
-- [ ] Mouse selection is broken due to entire TUI update:
- - By drawing only the lines that change, we can make the mouse selection not go away.
- - Use DRAW_COMPONENT_FLAG to let draw_tui know what needs to be updated.
- [ ] Change task order (use task_t tmp_task + memcpy);
- [ ] Create task using keys: `c` and `C`;
- [ ] Delete task using keys: `d` and `D`;