diff --git a/source/main.cpp b/source/main.cpp index 2c33558..53c6320 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -66,24 +66,26 @@ void export_result(const char * const result) { } } -void * async_query(void * arg) { +void * async(void * arg) { entry_t entry; - if (is_input_changed) { - query(rl_line_buffer, entry_lines, selection_offset); - is_input_changed = false; - } else { - requery(); + while (true) { + if (is_input_changed) { + query(rl_line_buffer, entry_lines, selection_offset); + is_input_changed = false; + } else { + requery(); + } + while (entry = get_entry(), entry.command != NULL) { + tui_append_back(entry); + } } - while (entry = get_entry(), entry.command != NULL) { - tui_append_back(entry); - } - tui_refresh(); return NULL; } signed main(const int argc, const char * const * const argv) { + extern void testtest(void); // NOTE: never returns on error parse_arguments(argc, argv); @@ -92,10 +94,13 @@ signed main(const int argc, const char * const * const argv) { tui_refresh(); pthread_t query_thread; + pthread_create(&query_thread, NULL, async, NULL); while (do_run) { - pthread_cancel(query_thread); - pthread_create(&query_thread, NULL, async_query, NULL); tui_take_input(); + if (is_input_changed) { + testtest(); + } + tui_refresh(); } query(rl_line_buffer, 1, selection_offset + selection_relative); diff --git a/source/storage.cpp b/source/storage.cpp index f257574..21d6165 100644 --- a/source/storage.cpp +++ b/source/storage.cpp @@ -137,6 +137,10 @@ void requery(void) { sqlite3_reset(*stmt); } +void testtest(void) { + sqlite3_interrupt(db); +} + entry_t get_entry(void) { if (sqlite3_step(*stmt) != SQLITE_ROW) { return (entry_t){ diff --git a/source/tui.cpp b/source/tui.cpp index 87a9caf..6a0af6e 100644 --- a/source/tui.cpp +++ b/source/tui.cpp @@ -29,7 +29,7 @@ int init_tui(void) { // Ncurses initscr(); nonl(); - cbreak(); + halfdelay(1); noecho(); curs_set(0); keypad(stdscr, TRUE); @@ -172,6 +172,7 @@ void tui_take_input(void) { case '\r': { do_run = false; } break; + case ERR: break; default: { input_available = true; rl_callback_read_char();