forked from fish-shell/fish-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.h
188 lines (150 loc) · 5.05 KB
/
input.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/** \file input.h
Functions for reading a character of input from stdin, using the
inputrc information for key bindings.
*/
#ifndef FISH_INPUT_H
#define FISH_INPUT_H
#include <wchar.h>
#include "input_common.h"
#define DEFAULT_BIND_MODE L"default"
#define FISH_BIND_MODE_VAR L"fish_bind_mode"
/**
Key codes for inputrc-style keyboard functions that are passed on
to the caller of input_read()
NOTE: IF YOU MODIFY THIS YOU MUST UPDATE THE name_arr AND code_arr VARIABLES TO MATCH!
*/
enum
{
R_BEGINNING_OF_LINE = R_NULL+10, /* This give input_common ten slots for lowlevel keycodes */
R_END_OF_LINE,
R_FORWARD_CHAR,
R_BACKWARD_CHAR,
R_FORWARD_WORD,
R_BACKWARD_WORD,
R_HISTORY_SEARCH_BACKWARD,
R_HISTORY_SEARCH_FORWARD,
R_DELETE_CHAR,
R_BACKWARD_DELETE_CHAR,
R_KILL_LINE,
R_YANK,
R_YANK_POP,
R_COMPLETE,
R_COMPLETE_AND_SEARCH,
R_BEGINNING_OF_HISTORY,
R_END_OF_HISTORY,
R_BACKWARD_KILL_LINE,
R_KILL_WHOLE_LINE,
R_KILL_WORD,
R_BACKWARD_KILL_WORD,
R_BACKWARD_KILL_PATH_COMPONENT,
R_HISTORY_TOKEN_SEARCH_BACKWARD,
R_HISTORY_TOKEN_SEARCH_FORWARD,
R_SELF_INSERT,
R_TRANSPOSE_CHARS,
R_TRANSPOSE_WORDS,
R_UPCASE_WORD,
R_DOWNCASE_WORD,
R_CAPITALIZE_WORD,
R_VI_ARG_DIGIT,
R_VI_DELETE_TO,
R_EXECUTE,
R_BEGINNING_OF_BUFFER,
R_END_OF_BUFFER,
R_REPAINT,
R_FORCE_REPAINT,
R_UP_LINE,
R_DOWN_LINE,
R_SUPPRESS_AUTOSUGGESTION,
R_ACCEPT_AUTOSUGGESTION,
R_BEGIN_SELECTION,
R_END_SELECTION,
R_KILL_SELECTION,
R_FORWARD_JUMP,
R_BACKWARD_JUMP,
R_AND,
R_CANCEL
};
wcstring describe_char(wint_t c);
#define R_MIN R_NULL
#define R_MAX R_AND
/**
Initialize the terminal by calling setupterm, and set up arrays
used by readch to detect escape sequences for special keys.
Before calling input_init, terminfo is not initialized and MUST not be used
*/
int input_init();
/**
free up memory used by terminal functions.
*/
void input_destroy();
/**
Read a character from fd 0. Try to convert some escape sequences
into character constants, but do not permanently block the escape
character.
This is performed in the same way vim does it, i.e. if an escape
character is read, wait for more input for a short time (a few
milliseconds). If more input is avaialable, it is assumed to be an
escape sequence for a special character (such as an arrow key), and
readch attempts to parse it. If no more input follows after the
escape key, it is assumed to be an actual escape key press, and is
returned as such.
*/
wint_t input_readch();
/**
Push a character or a readline function onto the stack of unread
characters that input_readch will return before actually reading from fd
0.
*/
void input_unreadch(wint_t ch);
/**
Add a key mapping from the specified sequence to the specified command
\param sequence the sequence to bind
\param command an input function that will be run whenever the key sequence occurs
*/
void input_mapping_add(const wchar_t *sequence, const wchar_t *command,
const wchar_t *mode = DEFAULT_BIND_MODE,
const wchar_t *new_mode = DEFAULT_BIND_MODE);
void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t commands_len,
const wchar_t *mode = DEFAULT_BIND_MODE, const wchar_t *new_mode = DEFAULT_BIND_MODE);
/**
Returns all mapping names
*/
wcstring_list_t input_mapping_get_names();
/**
Erase binding for specified key sequence
*/
bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode = DEFAULT_BIND_MODE);
/**
Gets the command bound to the specified key sequence. Returns true if it exists, false if not.
*/
bool input_mapping_get(const wcstring &sequence, wcstring_list_t *out_cmds, wcstring *out_mode, wcstring *out_new_mode);
/**
Return the current bind mode
*/
wcstring input_get_bind_mode();
/**
Set the current bind mode
*/
void input_set_bind_mode(const wcstring &bind_mode);
wchar_t input_function_pop_arg();
/**
Sets the return status of the most recently executed input function
*/
void input_function_set_status(bool status);
/**
Return the sequence for the terminfo variable of the specified name.
If no terminfo variable of the specified name could be found, return false and set errno to ENOENT.
If the terminfo variable does not have a value, return false and set errno to EILSEQ.
*/
bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq);
/** Return the name of the terminfo variable with the specified sequence */
bool input_terminfo_get_name(const wcstring &seq, wcstring &name);
/** Return a list of all known terminfo names */
wcstring_list_t input_terminfo_get_names(bool skip_null);
/** Returns the input function code for the given input function name. */
wchar_t input_function_get_code(const wcstring &name);
/** Returns a list of all existing input function names */
wcstring_list_t input_function_get_names(void);
/** Updates our idea of whether we support term256 */
void update_fish_term256();
#endif