commit - de27856787c352519320f213681df6c680a3d446
commit + 4bc446b95ba4642c1e00a9b27c9f0a8ed5d4f369
blob - 0a98f96df633498696facfea854575e69587cfe2
blob + a1e9b72200b10348435a9b151e55a7d8db2a689a
--- minibuffer.c
+++ minibuffer.c
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "compat.h"
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
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;
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
*/
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;
};
extern struct ministate ministate;
-extern struct buffer minibufferwin;
-
void recompute_completions(int);
void minibuffer_taint_hist(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
#include <unistd.h>
#include "defaults.h"
+#include "minibuffer.h"
#include "parser.h"
#include "telescope.h"
#include "ui.h"
blob - 6ab32c5924d9f7bf150c9b278655300438d409b0
blob + 8ad768fe50793930b1a5df786644d90b34322ffa
--- ui.c
+++ ui.c
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);
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;
}
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)) {
}
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)
ui_init()
{
setlocale(LC_ALL, "");
+
+ minibuffer_init();
TAILQ_INIT(&eecmd_history.head);
TAILQ_INIT(&ir_history.head);
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);
}
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)
{
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
};
extern struct thiskey thiskey;
-extern struct histhead eecmd_history,
- ir_history,
- lu_history,
- read_history;
-
extern struct tab *current_tab;
extern struct buffer helpwin;
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);
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 *);