Blame


1 6ab857d5 2024-01-23 op /*
2 6ab857d5 2024-01-23 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 6ab857d5 2024-01-23 op *
4 6ab857d5 2024-01-23 op * Permission to use, copy, modify, and distribute this software for any
5 6ab857d5 2024-01-23 op * purpose with or without fee is hereby granted, provided that the above
6 6ab857d5 2024-01-23 op * copyright notice and this permission notice appear in all copies.
7 6ab857d5 2024-01-23 op *
8 6ab857d5 2024-01-23 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 6ab857d5 2024-01-23 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 6ab857d5 2024-01-23 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 6ab857d5 2024-01-23 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 6ab857d5 2024-01-23 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 6ab857d5 2024-01-23 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 6ab857d5 2024-01-23 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 6ab857d5 2024-01-23 op */
16 6ab857d5 2024-01-23 op
17 6ab857d5 2024-01-23 op #ifndef MINIBUFFER_H
18 6ab857d5 2024-01-23 op #define MINIBUFFER_H
19 6ab857d5 2024-01-23 op
20 6ab857d5 2024-01-23 op #include "telescope.h"
21 6ab857d5 2024-01-23 op
22 6ab857d5 2024-01-23 op /* need to be true-ish */
23 6ab857d5 2024-01-23 op #define MB_READ 1
24 6ab857d5 2024-01-23 op #define MB_COMPREAD 2
25 6ab857d5 2024-01-23 op
26 6ab857d5 2024-01-23 op /*
27 6ab857d5 2024-01-23 op * Completion provider function. These functions are called
28 6ab857d5 2024-01-23 op * asynchronously. The function should compute the next completion
29 6ab857d5 2024-01-23 op * using the given parameter `state' and modify it eventually. To
30 6ab857d5 2024-01-23 op * signal the end of the completions, complfn should return NULL: the
31 6ab857d5 2024-01-23 op * value of state will then be discarded and the function never called
32 6ab857d5 2024-01-23 op * again. The second parameter is some extra metadata per-line; it'll
33 6ab857d5 2024-01-23 op * be available as line->data on the selected line during the
34 6ab857d5 2024-01-23 op * minibuffer lifecycle. The third parameter is an extra description
35 6ab857d5 2024-01-23 op * field for the current item.
36 6ab857d5 2024-01-23 op */
37 6ab857d5 2024-01-23 op typedef const char *(complfn)(void **, void **, const char **);
38 6ab857d5 2024-01-23 op
39 6ab857d5 2024-01-23 op struct hist;
40 6ab857d5 2024-01-23 op extern struct hist *eecmd_history;
41 6ab857d5 2024-01-23 op extern struct hist *ir_history;
42 6ab857d5 2024-01-23 op extern struct hist *lu_history;
43 6ab857d5 2024-01-23 op extern struct hist *read_history;
44 6ab857d5 2024-01-23 op
45 6ab857d5 2024-01-23 op struct ministate {
46 6ab857d5 2024-01-23 op char *curmesg;
47 6ab857d5 2024-01-23 op
48 6ab857d5 2024-01-23 op char prompt[64];
49 0fceedb5 2024-06-07 op void (*donefn)(const char *);
50 6ab857d5 2024-01-23 op void (*abortfn)(void);
51 6ab857d5 2024-01-23 op
52 6ab857d5 2024-01-23 op char buf[1025];
53 6ab857d5 2024-01-23 op struct line line;
54 6ab857d5 2024-01-23 op struct vline vline;
55 6ab857d5 2024-01-23 op struct buffer buffer;
56 6ab857d5 2024-01-23 op
57 6ab857d5 2024-01-23 op struct hist *hist;
58 6ab857d5 2024-01-23 op int editing;
59 6ab857d5 2024-01-23 op
60 6ab857d5 2024-01-23 op struct {
61 6ab857d5 2024-01-23 op struct buffer buffer;
62 6ab857d5 2024-01-23 op complfn *fn;
63 6ab857d5 2024-01-23 op void *data;
64 6ab857d5 2024-01-23 op int must_select;
65 6ab857d5 2024-01-23 op } compl;
66 6ab857d5 2024-01-23 op };
67 6ab857d5 2024-01-23 op extern struct ministate ministate;
68 6ab857d5 2024-01-23 op
69 6ab857d5 2024-01-23 op extern struct buffer minibufferwin;
70 6ab857d5 2024-01-23 op extern int in_minibuffer;
71 6ab857d5 2024-01-23 op
72 6ab857d5 2024-01-23 op void recompute_completions(int);
73 6ab857d5 2024-01-23 op int minibuffer_insert_current_candidate(void);
74 6ab857d5 2024-01-23 op void minibuffer_taint_hist(void);
75 0fceedb5 2024-06-07 op void minibuffer_confirm(void);
76 6ab857d5 2024-01-23 op void minibuffer_self_insert(void);
77 6ab857d5 2024-01-23 op void sensible_self_insert(void);
78 0fceedb5 2024-06-07 op void eecmd_select(const char *);
79 0fceedb5 2024-06-07 op void ir_select_gemini(const char *);
80 0fceedb5 2024-06-07 op void ir_select_reply(const char *);
81 0fceedb5 2024-06-07 op void ir_select_gopher(const char *);
82 0fceedb5 2024-06-07 op void lu_select(const char *);
83 0fceedb5 2024-06-07 op void bp_select(const char *);
84 0fceedb5 2024-06-07 op void ts_select(const char *);
85 0fceedb5 2024-06-07 op void ls_select(const char *);
86 0fceedb5 2024-06-07 op void swiper_select(const char *);
87 0fceedb5 2024-06-07 op void toc_select(const char *);
88 0fceedb5 2024-06-07 op void uc_select(const char *);
89 0fceedb5 2024-06-07 op void search_select(const char *);
90 6ab857d5 2024-01-23 op
91 dfd1efcc 2024-06-23 op struct minibuffer {
92 dfd1efcc 2024-06-23 op void (*self_insert)(void);
93 dfd1efcc 2024-06-23 op void (*done)(const char *);
94 dfd1efcc 2024-06-23 op void (*abort)(void);
95 dfd1efcc 2024-06-23 op struct hist *history;
96 dfd1efcc 2024-06-23 op complfn *complfn;
97 dfd1efcc 2024-06-23 op void *compldata;
98 dfd1efcc 2024-06-23 op int must_select;
99 dfd1efcc 2024-06-23 op const char *input;
100 dfd1efcc 2024-06-23 op };
101 6ab857d5 2024-01-23 op
102 dfd1efcc 2024-06-23 op void enter_minibuffer(struct minibuffer *, const char *, ...);
103 dfd1efcc 2024-06-23 op
104 6ab857d5 2024-01-23 op void exit_minibuffer(void);
105 057e7eb6 2024-06-22 op void yornp(const char *, void (*)(int, void *), void *);
106 6ab857d5 2024-01-23 op
107 6ab857d5 2024-01-23 op /*
108 6ab857d5 2024-01-23 op * minibuffer_read asks the user for something using the minibuffer.
109 6ab857d5 2024-01-23 op * The first argument is the string prompt. The second and third are
110 6ab857d5 2024-01-23 op * the callback to call when done and the data; the callback function
111 6ab857d5 2024-01-23 op * can't be NULL.
112 6ab857d5 2024-01-23 op */
113 6ab857d5 2024-01-23 op void minibuffer_read(const char *,
114 479b240a 2024-06-25 op void (*)(const char *, struct tab *), struct tab *, const char *);
115 6ab857d5 2024-01-23 op
116 6ab857d5 2024-01-23 op void vmessage(const char *, va_list);
117 6ab857d5 2024-01-23 op void message(const char *, ...) __attribute__((format(printf, 1, 2)));
118 6ab857d5 2024-01-23 op void minibuffer_init(void);
119 6ab857d5 2024-01-23 op
120 6ab857d5 2024-01-23 op #endif