aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c41
1 files changed, 26 insertions, 15 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;
}