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 65601367 2021-07-14 op * be available as line->meta.data on the selected line during the
34 65601367 2021-07-14 op * minibuffer lifecycle.
35 b1e1e41a 2021-07-14 op */
36 65601367 2021-07-14 op typedef const char *(complfn)(void **, void **);
37 e5a2797f 2021-07-13 op
38 b1e1e41a 2021-07-14 op struct ministate {
39 b1e1e41a 2021-07-14 op char *curmesg;
40 b1e1e41a 2021-07-14 op
41 b1e1e41a 2021-07-14 op char prompt[64];
42 b1e1e41a 2021-07-14 op void (*donefn)(void);
43 b1e1e41a 2021-07-14 op void (*abortfn)(void);
44 b1e1e41a 2021-07-14 op
45 b1e1e41a 2021-07-14 op char buf[1025];
46 b1e1e41a 2021-07-14 op struct line line;
47 b1e1e41a 2021-07-14 op struct vline vline;
48 b1e1e41a 2021-07-14 op struct buffer buffer;
49 b1e1e41a 2021-07-14 op
50 b1e1e41a 2021-07-14 op struct histhead *history;
51 b1e1e41a 2021-07-14 op struct hist *hist_cur;
52 b1e1e41a 2021-07-14 op size_t hist_off;
53 b1e1e41a 2021-07-14 op
54 b1e1e41a 2021-07-14 op struct {
55 b1e1e41a 2021-07-14 op struct buffer buffer;
56 b1e1e41a 2021-07-14 op complfn *fn;
57 b1e1e41a 2021-07-14 op void *data;
58 b1e1e41a 2021-07-14 op } compl;
59 b1e1e41a 2021-07-14 op };
60 b1e1e41a 2021-07-14 op extern struct ministate ministate;
61 b1e1e41a 2021-07-14 op
62 b1e1e41a 2021-07-14 op extern struct buffer minibufferwin;
63 b1e1e41a 2021-07-14 op
64 b1e1e41a 2021-07-14 op void recompute_completions(int);
65 b1e1e41a 2021-07-14 op
66 77a48529 2021-07-14 op void minibuffer_taint_hist(void);
67 77a48529 2021-07-14 op void minibuffer_self_insert(void);
68 40fbc354 2021-07-14 op void sensible_self_insert(void);
69 77a48529 2021-07-14 op void eecmd_self_insert(void);
70 77a48529 2021-07-14 op void eecmd_select(void);
71 77a48529 2021-07-14 op void ir_self_insert(void);
72 77a48529 2021-07-14 op void ir_select(void);
73 77a48529 2021-07-14 op void lu_select(void);
74 77a48529 2021-07-14 op void bp_select(void);
75 77a48529 2021-07-14 op void ts_select(void);
76 753c6ac7 2021-07-14 op void ls_select(void);
77 753c6ac7 2021-07-14 op void swiper_select(void);
78 edd9a650 2021-07-15 op void toc_select(void);
79 77a48529 2021-07-14 op
80 450a89f7 2021-07-12 op void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void),
81 e5a2797f 2021-07-13 op struct histhead *,
82 e5a2797f 2021-07-13 op complfn *, void *);
83 e5a2797f 2021-07-13 op
84 450a89f7 2021-07-12 op void exit_minibuffer(void);
85 450a89f7 2021-07-12 op void yornp(const char *, void (*)(int, struct tab *), struct tab *);
86 e5a2797f 2021-07-13 op
87 e5a2797f 2021-07-13 op /*
88 e5a2797f 2021-07-13 op * completing_read asks the user for something using the minibuffer.
89 e5a2797f 2021-07-13 op * The first argument is the string prompt. The second and third are
90 e5a2797f 2021-07-13 op * the callback to call when done and the data; the callback function
91 b1e1e41a 2021-07-14 op * can't be NULL.
92 e5a2797f 2021-07-13 op */
93 450a89f7 2021-07-12 op void completing_read(const char *,
94 b1e1e41a 2021-07-14 op void (*)(const char *, struct tab *), struct tab *);
95 450a89f7 2021-07-12 op
96 450a89f7 2021-07-12 op #endif