aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c48
-rw-r--r--readme.md6
2 files changed, 37 insertions, 17 deletions
diff --git a/main.c b/main.c
index b6cbda1..cff3639 100644
--- a/main.c
+++ b/main.c
@@ -567,7 +567,7 @@ void update_timers(database_st *db) {
while (start_time < stop_time) {
start_week_day = localtime(&start_time)->tm_wday;
-
+
// Get next day in local time.
struct tm *start_of_day_tm = localtime(&start_time);
start_of_day_tm->tm_sec = 0;
@@ -1032,10 +1032,13 @@ int main(int argc, char *argv[]) {
ungetch(KEY_RESIZE);
for (int key; (key = getch()) != 'q'; ) {
-
+
timeout(INPUT_AWAIT_INF);
task_st *active_task = get_active_task(db);
task_st *selected_task = get_selected_task(db);
+ int selected_task_row = (db->selected_task % NUM_TABLE_ROWS) + NUM_HEADER_ROWS;
+ int selected_task_theme = selected_task == active_task ? THEME_E : THEME_D;
+
update_timers(&database);
switch(key) {
@@ -1049,7 +1052,7 @@ int main(int argc, char *argv[]) {
case KEY_RESIZE: {
clear();
getmaxyx(stdscr, size_y, size_x);
- string_buffer = realloc(string_buffer, 511 | MAX_TASK_NAME | size_x); // TODO This realloc sucks.
+ string_buffer = realloc(string_buffer, 511 | MAX_TASK_NAME | (size_x + 1)); // TODO This realloc sucks.
break;
}
@@ -1079,29 +1082,46 @@ int main(int argc, char *argv[]) {
if (selected_task == NULL) {
break;
}
- // rename stuff
- int row = (db->selected_task % NUM_TABLE_ROWS) + NUM_HEADER_ROWS;
- attron(COLOR_PAIR(selected_task == active_task ? THEME_E : THEME_D) | A_BOLD);
- mvaddch(row, 0, ACS_DIAMOND);
- clrtoeol();
- mvaddch(row, size_x-1, ACS_VLINE);
+
+ // Prepare row to input new task name.
+ attron(COLOR_PAIR(selected_task_theme) | A_BOLD);
+ mvaddch(selected_task_row, 0, ACS_DIAMOND);
+ sprintf(string_buffer, "%*s", size_x - 2, "");
+ addstr(string_buffer);
+
+ // Get new task name.
curs_set(1);
-
- mvgetnstr(row, 1, string_buffer, MAX_TASK_NAME-1);
+ mvgetnstr(selected_task_row, 1, string_buffer, MAX_TASK_NAME-1);
+ curs_set(0);
+
+ // Apply new task name.
if (is_empty_string(string_buffer) == false) {
memcpy(selected_task->name, string_buffer, MAX_TASK_NAME);
}
- curs_set(0);
attrset(A_NORMAL);
break;
}
case KEY_DC: { // Delete
- if (selected_task == NULL) {
+ if (selected_task == NULL || selected_task == active_task) {
break;
}
- delete_task(db, selected_task);
+
+ const char *message = "Press enter to delete.";
+ const size_t length = strlen(message);
+ int left_padding = ((size_x - 2) - length) / 2;
+ int right_padding = ((size_x - 2) - length) - left_padding;
+ sprintf(string_buffer, "%*s%s%*s", left_padding, "", message, right_padding, "");
+
+ attron(COLOR_PAIR(selected_task_theme) | A_BOLD);
+ mvaddch(selected_task_row, 0, ACS_DIAMOND);
+ addstr(string_buffer);
+ attrset(A_NORMAL);
+
+ if (getch() == '\n') {
+ delete_task(db, selected_task);
+ }
break;
}
diff --git a/readme.md b/readme.md
index c68ca55..7b65d00 100644
--- a/readme.md
+++ b/readme.md
@@ -42,9 +42,9 @@ Task Time Tracker
- [x] Allow usage of `ttt: ./ttt --dpath ./` to change the app folder: To changes app data path change the environment variable HOME (USERPROFILE for windows users).
- [x] Clone (replicate) task; If task is active, mark newly created task as inactive;
- [x] Check if next/previous is safe against overflows/underflows using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
-- [ ] Confirm delete_task operation.
- - For actions that require confirmation, show confirmation message on selected line (horizontally centered) saying "Press enter to delete/archive. Any other to cancel." and await on `getch` for a `\n`. On archiving action this should only occur if the task is active. Use red/black for confirmation message surrounded by diamonds. Implement this using a function `bool get_confirmation(const char *message)`.
-- [ ] Check totals update speedup using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
+- [x] Confirm delete_task operation by show confirmation message on selected line (horizontally centered).
+- [x] Check totals update speedup using https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
+ - For 1M entries, generic C code runs in 12.0ms and builtins runs in 9.5ms. Not worth the effort.
- [ ] Change task order (using task_t tmp_task + memcpy);
- [ ] Allow to jump to specific task by index number using key `g` and `G`;
- [ ] Add/remove time using keys: `F3`;