commit e5a2797faaeff6b9a4012a166ab9caa6c3634a5d from: Omar Polo date: Tue Jul 13 16:31:11 2021 UTC foreshadowing: the "real" completing_read commit - b3884fbee299f6fe654945d9e604f954f3e3c7e1 commit + e5a2797faaeff6b9a4012a166ab9caa6c3634a5d blob - 4921c7cc43fd690351ac45d913b66f08dfe8d63a blob + 42c6cf2f7c3255420553a008549209927297e980 --- cmd.c +++ cmd.c @@ -18,6 +18,7 @@ #include #include +#include "defaults.h" #include "minibuffer.h" #include "telescope.h" #include "ui.h" @@ -346,7 +347,7 @@ cmd_execute_extended_command(struct buffer *buffer) } enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer, - &eecmd_history); + &eecmd_history, NULL, NULL); len = sizeof(ministate.prompt); strlcpy(ministate.prompt, "", len); @@ -481,7 +482,7 @@ cmd_load_url(struct buffer *buffer) } enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer, - &lu_history); + &lu_history, NULL, NULL); strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt)); strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf)); cmd_move_end_of_line(&ministate.buffer); @@ -498,7 +499,7 @@ cmd_load_current_url(struct buffer *buffer) } enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer, - &lu_history); + &lu_history, NULL, NULL); strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt)); strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf)); ministate.buffer.cpoff = utf8_cplen(ministate.buf); @@ -509,7 +510,8 @@ cmd_bookmark_page(struct buffer *buffer) { struct tab *tab = current_tab(); - enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL); + enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL, + NULL, NULL); strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt)); strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf)); ministate.buffer.cpoff = utf8_cplen(ministate.buf); blob - 2fe5346dd4f33ba360dc7ebbe925293061ce3f55 blob + 5354c5fd3f762db6e1f280b5d2f04c8d41708314 --- minibuffer.c +++ minibuffer.c @@ -230,7 +230,8 @@ read_select(void) void enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void), - void (*abortfn)(void), struct histhead *hist) + void (*abortfn)(void), struct histhead *hist, + complfn *complfn, void *compldata) { in_minibuffer = 1; base_map = &minibuffer_map; @@ -273,7 +274,7 @@ yornp(const char *prompt, void (*fn)(int, struct tab*) yornp_cb = fn; yornp_data = data; enter_minibuffer(yornp_self_insert, yornp_self_insert, - yornp_abort, NULL); + yornp_abort, NULL, NULL, NULL); len = sizeof(ministate.prompt); strlcpy(ministate.prompt, prompt, len); @@ -285,7 +286,7 @@ yornp(const char *prompt, void (*fn)(int, struct tab*) */ void completing_read(const char *prompt, void (*fn)(const char *, struct tab *), - struct tab *data) + struct tab *data, complfn *complfn, void *compldata) { size_t len; @@ -295,7 +296,7 @@ completing_read(const char *prompt, void (*fn)(const c read_cb = fn; read_data = data; enter_minibuffer(read_self_insert, read_select, read_abort, - &read_history); + &read_history, complfn, compldata); len = sizeof(ministate.prompt); strlcpy(ministate.prompt, prompt, len); blob - 0f071031d53a8afd61783699b42ee014688d2710 blob + e6577cbd7191c8338c24499cb418c43757f399fd --- minibuffer.h +++ minibuffer.h @@ -19,12 +19,29 @@ #include "telescope.h" +/* need to be true-ish */ +#define MB_READ 1 +#define MB_COMPREAD 2 + +typedef char *(complfn)(void *); + void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), - struct histhead *); + struct histhead *, + complfn *, void *); + void exit_minibuffer(void); void yornp(const char *, void (*)(int, struct tab *), struct tab *); + +/* + * completing_read asks the user for something using the minibuffer. + * The first argument is the string prompt. The second and third are + * the callback to call when done and the data; the callback function + * can't be NULL. The last two arguments are the completion function + * and its data; if not given, no completion will be shown. The + * function providing the completion will be called asynchronously. + */ void completing_read(const char *, - void (*)(const char *, struct tab *), - struct tab *); + void (*)(const char *, struct tab *), struct tab *, + complfn *, void *); #endif blob - e1aaadd77b892a565108349970e26450e6f63462 blob + c976d386465eb4267bed7caa84ca7f6c1671f0a1 --- ui.c +++ ui.c @@ -81,7 +81,7 @@ struct thiskey thiskey; static struct event resizeev; static struct timeval resize_timer = { 0, 250000 }; -static WINDOW *tabline, *body, *modeline, *echoarea; +static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer; int body_lines, body_cols; @@ -1106,6 +1106,8 @@ ui_init() if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL) return 0; if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL) + return 0; + if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL) return 0; if ((help = newwin(1, 1, 1, 0)) == NULL) return 0; @@ -1191,7 +1193,7 @@ ui_require_input(struct tab *tab, int hide) switch_to_tab(tab); enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer, - &ir_history); + &ir_history, NULL, NULL); strlcpy(ministate.prompt, "Input required: ", sizeof(ministate.prompt)); redraw_tab(tab); @@ -1209,7 +1211,7 @@ void ui_read(const char *prompt, void (*fn)(const char*, struct tab *), struct tab *data) { - completing_read(prompt, fn, data); + completing_read(prompt, fn, data, NULL, NULL); redraw_tab(current_tab()); }