+quit while preserving the input

This commit is contained in:
anon 2024-10-07 18:16:01 +02:00
parent 1ee6df5f37
commit 406ebec75b
2 changed files with 20 additions and 7 deletions

View File

@ -7,8 +7,9 @@
#include "storage.h"
#include "tui.h"
bool do_run = true;
bool do_execute = false;
bool do_run = true; // do run program
bool do_execute = false; // do execute resulting command
bool do_select = true; // do overwrite input with selection
void init(void);
void deinit(void);
@ -106,8 +107,14 @@ signed main(const int argc, const char * const * const argv) {
}
pthread_join(query_thread, NULL);
query(get_input_line(), 1, selection_offset + selection_relative);
export_result(get_entry().command);
const char * command;
if (do_select) {
query(get_input_line(), 1, selection_offset + selection_relative);
command = get_entry().command;
} else {
command = get_input_line();
}
export_result(command);
deinit();

View File

@ -6,8 +6,6 @@
#include "caret_notater.h"
extern bool do_execute;
/* I fucking hate readline.
* Apparently the only way to set an initial value is using a hook.
* What makes this extra painful is that readline cannot be explicitly
@ -240,6 +238,8 @@ void tui_refresh(void) {
void tui_take_input(void) {
extern bool do_run;
extern bool do_execute;
extern bool do_select;
const size_t paging_size = entry_lines / 2;
input = wgetch(stdscr);
@ -302,7 +302,13 @@ void tui_take_input(void) {
// quit and insert current selection
case '\t': {
do_execute = false;
do_run = false;
do_run = false;
} break;
// quit and preserve input
case ESC: {
do_select = false;
do_execute = false;
do_run = false;
} break;
// edit cursor left
case KEY_LEFT: {