commit 4bc446b95ba4642c1e00a9b27c9f0a8ed5d4f369 from: Omar Polo date: Wed Jul 21 14:15:12 2021 UTC reorder minibuffer stuff and while there also rename the bogus completing_read to minibuffer_read. To get a ``completing-read'' one has to call enter_minibuffer with the right parameters. commit - de27856787c352519320f213681df6c680a3d446 commit + 4bc446b95ba4642c1e00a9b27c9f0a8ed5d4f369 blob - 0a98f96df633498696facfea854575e69587cfe2 blob + a1e9b72200b10348435a9b151e55a7d8db2a689a --- minibuffer.c +++ minibuffer.c @@ -14,6 +14,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "compat.h" + +#include #include #include @@ -28,6 +31,10 @@ static void yornp_abort(void); static void read_self_insert(void); static void read_abort(void); static void read_select(void); +static void handle_clear_echoarea(int, short, void *); + +static struct event clechoev; +static struct timeval clechoev_timer = { 5, 0 }; static void (*yornp_cb)(int, struct tab *); static struct tab *yornp_data; @@ -464,11 +471,8 @@ yornp(const char *prompt, void (*fn)(int, struct tab*) strlcat(ministate.prompt, " (y or n) ", len); } -/* - * Not yet "completing", but soon maybe... - */ -void -completing_read(const char *prompt, void (*fn)(const char *, struct tab *), +void +minibuffer_read(const char *prompt, void (*fn)(const char *, struct tab *), struct tab *data) { size_t len; @@ -484,4 +488,50 @@ completing_read(const char *prompt, void (*fn)(const c len = sizeof(ministate.prompt); strlcpy(ministate.prompt, prompt, len); strlcat(ministate.prompt, ": ", len); +} + +static void +handle_clear_echoarea(int fd, short ev, void *d) +{ + free(ministate.curmesg); + ministate.curmesg = NULL; + + ui_after_message_hook(); +} + +void +vmessage(const char *fmt, va_list ap) +{ + if (evtimer_pending(&clechoev, NULL)) + evtimer_del(&clechoev); + + free(ministate.curmesg); + ministate.curmesg = NULL; + + if (fmt != NULL) { + evtimer_set(&clechoev, handle_clear_echoarea, NULL); + evtimer_add(&clechoev, &clechoev_timer); + + /* TODO: what to do if the allocation fails here? */ + if (vasprintf(&ministate.curmesg, fmt, ap) == -1) + ministate.curmesg = NULL; + } + + ui_after_message_hook(); } + +void +message(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vmessage(fmt, ap); + va_end(ap); +} + +void +minibuffer_init(void) +{ + evtimer_set(&clechoev, handle_clear_echoarea, NULL); +} blob - e07841bc3b4eb1348dfa5ca514d0e9c5272ddbc6 blob + 3bffc8ee89aba97615b924dcda611bab2c6983d2 --- minibuffer.h +++ minibuffer.h @@ -36,6 +36,13 @@ */ typedef const char *(complfn)(void **, void **, const char **); +extern struct histhead eecmd_history, + ir_history, + lu_history, + read_history; + +extern struct buffer minibufferwin; + struct ministate { char *curmesg; @@ -60,8 +67,6 @@ struct ministate { }; extern struct ministate ministate; -extern struct buffer minibufferwin; - void recompute_completions(int); void minibuffer_taint_hist(void); @@ -79,19 +84,22 @@ void swiper_select(void); void toc_select(void); void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), - struct histhead *, - complfn *, void *); + 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. + * minibuffer_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. */ -void completing_read(const char *, +void minibuffer_read(const char *, void (*)(const char *, struct tab *), struct tab *); +void vmessage(const char *, va_list); +void message(const char *, ...) __attribute__((format(printf, 1, 2))); +void minibuffer_init(void); + #endif blob - 9eab390085611afbe1d8be27a1f96798f25041c3 blob + 7ca3e113ed07fc25c310639fd6338303ec8084af --- telescope.c +++ telescope.c @@ -26,6 +26,7 @@ #include #include "defaults.h" +#include "minibuffer.h" #include "parser.h" #include "telescope.h" #include "ui.h" blob - 6ab32c5924d9f7bf150c9b278655300438d409b0 blob + 8ad768fe50793930b1a5df786644d90b34322ffa --- ui.c +++ ui.c @@ -52,7 +52,6 @@ static void restore_curs_x(struct buffer *); static int readkey(void); static void dispatch_stdio(int, short, void*); -static void handle_clear_echoarea(int, short, void*); static void handle_resize(int, short, void*); static void handle_resize_nodelay(int, short, void*); static void rearrange_windows(void); @@ -98,8 +97,6 @@ int help_lines, help_cols; static int side_window; -static struct event clechoev; -static struct timeval clechoev_timer = { 5, 0 }; static struct timeval loadingev_timer = { 0, 250000 }; static uint32_t tab_counter; @@ -278,16 +275,6 @@ done: } static void -handle_clear_echoarea(int fd, short ev, void *d) -{ - free(ministate.curmesg); - ministate.curmesg = NULL; - - redraw_minibuffer(); - place_cursor(0); -} - -static void handle_resize(int sig, short ev, void *d) { if (event_pending(&resizeev, EV_TIMEOUT, NULL)) { @@ -894,38 +881,6 @@ redraw_tab(struct tab *tab) } void -vmessage(const char *fmt, va_list ap) -{ - if (evtimer_pending(&clechoev, NULL)) - evtimer_del(&clechoev); - - free(ministate.curmesg); - ministate.curmesg = NULL; - - if (fmt != NULL) { - evtimer_set(&clechoev, handle_clear_echoarea, NULL); - evtimer_add(&clechoev, &clechoev_timer); - - /* TODO: what to do if the allocation fails here? */ - if (vasprintf(&ministate.curmesg, fmt, ap) == -1) - ministate.curmesg = NULL; - } - - redraw_minibuffer(); - place_cursor(0); -} - -void -message(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vmessage(fmt, ap); - va_end(ap); -} - -void start_loading_anim(struct tab *tab) { if (tab->loading_anim) @@ -1079,6 +1034,8 @@ int ui_init() { setlocale(LC_ALL, ""); + + minibuffer_init(); TAILQ_INIT(&eecmd_history.head); TAILQ_INIT(&ir_history.head); @@ -1140,11 +1097,6 @@ ui_init() mvwprintw(body, 0, 0, ""); - /* - * Dummy so libevent2 won't complain that no event_base is set - * when checking event_pending for the first time - */ - evtimer_set(&clechoev, handle_clear_echoarea, NULL); evtimer_set(&resizeev, handle_resize, NULL); event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL); @@ -1230,6 +1182,13 @@ ui_require_input(struct tab *tab, int hide) } void +ui_after_message_hook(void) +{ + redraw_minibuffer(); + place_cursor(0); +} + +void ui_yornp(const char *prompt, void (*fn)(int, struct tab *), struct tab *data) { @@ -1241,7 +1200,7 @@ void ui_read(const char *prompt, void (*fn)(const char*, struct tab *), struct tab *data) { - completing_read(prompt, fn, data); + minibuffer_read(prompt, fn, data); redraw_tab(current_tab); } blob - d9724d853f21354625b8f284d0a8e1e6d3c9c713 blob + 7973a0dca3f3a20529e0a4bf54fa434db5db810d --- ui.h +++ ui.h @@ -93,11 +93,6 @@ struct thiskey { }; extern struct thiskey thiskey; -extern struct histhead eecmd_history, - ir_history, - lu_history, - read_history; - extern struct tab *current_tab; extern struct buffer helpwin; @@ -107,14 +102,13 @@ void save_excursion(struct excursion *, struct buffe void restore_excursion(struct excursion *, struct buffer *); void global_key_unbound(void); struct vline *adjust_line(struct vline *, struct buffer *); -void vmessage(const char *, va_list); -void message(const char *, ...) __attribute__((format(printf, 1, 2))); void start_loading_anim(struct tab *); void load_url_in_tab(struct tab *, const char *, const char *); void switch_to_tab(struct tab *); struct buffer *current_buffer(void); struct tab *new_tab(const char *, const char *base); unsigned int tab_new_id(void); + int ui_print_colors(void); int ui_init(void); void ui_main_loop(void); @@ -123,6 +117,7 @@ void ui_on_tab_refresh(struct tab *); const char *ui_keyname(int); void ui_toggle_side_window(void); void ui_schedule_redraw(void); +void ui_after_message_hook(void); void ui_require_input(struct tab *, int); void ui_read(const char *, void (*)(const char *, struct tab *), struct tab *); void ui_yornp(const char *, void (*)(int, struct tab *), struct tab *);