Blame


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