2005-09-20 21:26:39 +08:00
|
|
|
/** \file input.h
|
|
|
|
|
|
|
|
Functions for reading a character of input from stdin, using the
|
|
|
|
inputrc information for key bindings.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_INPUT_H
|
|
|
|
#define FISH_INPUT_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2014-09-23 12:04:06 +08:00
|
|
|
#include <utility>
|
2006-03-10 21:38:09 +08:00
|
|
|
#include "input_common.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2013-12-31 08:52:41 +08:00
|
|
|
|
|
|
|
#define DEFAULT_BIND_MODE L"default"
|
2014-01-19 17:27:39 +08:00
|
|
|
#define FISH_BIND_MODE_VAR L"fish_bind_mode"
|
2013-12-31 08:52:41 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
|
|
|
Key codes for inputrc-style keyboard functions that are passed on
|
|
|
|
to the caller of input_read()
|
2014-04-01 01:01:39 +08:00
|
|
|
|
2014-01-22 08:08:35 +08:00
|
|
|
NOTE: IF YOU MODIFY THIS YOU MUST UPDATE THE name_arr AND code_arr VARIABLES TO MATCH!
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
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,
|
2014-01-27 16:56:13 +08:00
|
|
|
R_COMPLETE_AND_SEARCH,
|
2012-11-19 08:30:30 +08:00
|
|
|
R_BEGINNING_OF_HISTORY,
|
|
|
|
R_END_OF_HISTORY,
|
|
|
|
R_BACKWARD_KILL_LINE,
|
|
|
|
R_KILL_WHOLE_LINE,
|
|
|
|
R_KILL_WORD,
|
|
|
|
R_BACKWARD_KILL_WORD,
|
2012-12-21 09:45:35 +08:00
|
|
|
R_BACKWARD_KILL_PATH_COMPONENT,
|
2012-11-19 08:30:30 +08:00
|
|
|
R_HISTORY_TOKEN_SEARCH_BACKWARD,
|
|
|
|
R_HISTORY_TOKEN_SEARCH_FORWARD,
|
|
|
|
R_SELF_INSERT,
|
2013-05-21 03:42:34 +08:00
|
|
|
R_TRANSPOSE_CHARS,
|
2013-05-28 05:25:55 +08:00
|
|
|
R_TRANSPOSE_WORDS,
|
2013-09-10 00:46:16 +08:00
|
|
|
R_UPCASE_WORD,
|
|
|
|
R_DOWNCASE_WORD,
|
|
|
|
R_CAPITALIZE_WORD,
|
2012-11-19 08:30:30 +08:00
|
|
|
R_VI_ARG_DIGIT,
|
|
|
|
R_VI_DELETE_TO,
|
|
|
|
R_EXECUTE,
|
|
|
|
R_BEGINNING_OF_BUFFER,
|
|
|
|
R_END_OF_BUFFER,
|
|
|
|
R_REPAINT,
|
2013-12-31 21:53:29 +08:00
|
|
|
R_FORCE_REPAINT,
|
2012-11-19 08:30:30 +08:00
|
|
|
R_UP_LINE,
|
|
|
|
R_DOWN_LINE,
|
|
|
|
R_SUPPRESS_AUTOSUGGESTION,
|
2014-01-01 07:11:32 +08:00
|
|
|
R_ACCEPT_AUTOSUGGESTION,
|
2014-01-15 22:07:22 +08:00
|
|
|
R_BEGIN_SELECTION,
|
2014-01-18 17:18:29 +08:00
|
|
|
R_END_SELECTION,
|
2014-01-22 17:00:44 +08:00
|
|
|
R_KILL_SELECTION,
|
|
|
|
R_FORWARD_JUMP,
|
2014-01-23 17:23:04 +08:00
|
|
|
R_BACKWARD_JUMP,
|
2014-03-30 05:19:45 +08:00
|
|
|
R_AND,
|
2014-01-27 18:17:31 +08:00
|
|
|
R_CANCEL
|
2014-01-22 08:08:35 +08:00
|
|
|
};
|
|
|
|
|
2014-02-13 04:49:32 +08:00
|
|
|
wcstring describe_char(wint_t c);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2014-01-01 07:11:32 +08:00
|
|
|
#define R_MIN R_NULL
|
2014-09-22 11:54:44 +08:00
|
|
|
#define R_MAX R_CANCEL
|
2014-01-01 07:11:32 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
|
|
|
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.
|
Fix `commandline` behavior in bind functions
When a key is bound to a fish function, if that function invokes
`commandline`, it gets a stale copy of the commandline. This is because
any keys passed to `self-insert` (the default) don't actually get added
to the commandline until a special character is processed, such as the
R_NULL that gets returned after running a binding for a fish command.
To fix this, don't allow fish commands to be run for bindings if we're
processing more than one key. When a key wants to invoke a fish command,
instead we push the invocation sequence back onto the input, followed by
an R_NULL, and return. This causes the input loop to break out and
update the commandline. When it starts up again, it will re-process the
keys and invoke the fish command.
This is primarily an issue with pasting text that includes bound keys in
it. Typed text is slow enough that fish will update the commandline
between each character.
---
I don't know of any way to write a test for this, but the issue can be
reproduced as follows:
> bind _ 'commandline -i _'
This binds _ to a command that inserts _. Typing the following works:
> echo wat_is_it
But if you copy that line and paste it instead of typing it, the end
result looks like
> _echo wat_isit
With this fix in place, the pasted output correctly matches the typed
output.
2014-08-23 05:02:29 +08:00
|
|
|
|
|
|
|
The argument determines whether fish commands are allowed to be run
|
|
|
|
as bindings. If false, when a character is encountered that would
|
|
|
|
invoke a fish command, it is unread and R_NULL is returned.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
Fix `commandline` behavior in bind functions
When a key is bound to a fish function, if that function invokes
`commandline`, it gets a stale copy of the commandline. This is because
any keys passed to `self-insert` (the default) don't actually get added
to the commandline until a special character is processed, such as the
R_NULL that gets returned after running a binding for a fish command.
To fix this, don't allow fish commands to be run for bindings if we're
processing more than one key. When a key wants to invoke a fish command,
instead we push the invocation sequence back onto the input, followed by
an R_NULL, and return. This causes the input loop to break out and
update the commandline. When it starts up again, it will re-process the
keys and invoke the fish command.
This is primarily an issue with pasting text that includes bound keys in
it. Typed text is slow enough that fish will update the commandline
between each character.
---
I don't know of any way to write a test for this, but the issue can be
reproduced as follows:
> bind _ 'commandline -i _'
This binds _ to a command that inserts _. Typing the following works:
> echo wat_is_it
But if you copy that line and paste it instead of typing it, the end
result looks like
> _echo wat_isit
With this fix in place, the pasted output correctly matches the typed
output.
2014-08-23 05:02:29 +08:00
|
|
|
wint_t input_readch(bool allow_commands = true);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Push a character or a readline function onto the stack of unread
|
|
|
|
characters that input_readch will return before actually reading from fd
|
2012-11-18 18:23:22 +08:00
|
|
|
0.
|
2006-01-24 04:40:14 +08:00
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
void input_unreadch(wint_t ch);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-14 00:47:47 +08:00
|
|
|
Add a key mapping from the specified sequence to the specified command
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2008-01-14 00:47:47 +08:00
|
|
|
\param sequence the sequence to bind
|
|
|
|
\param command an input function that will be run whenever the key sequence occurs
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2013-12-31 08:52:41 +08:00
|
|
|
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);
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2014-01-01 07:11:32 +08:00
|
|
|
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);
|
|
|
|
|
2014-09-23 12:04:06 +08:00
|
|
|
struct input_mapping_name_t {
|
|
|
|
wcstring seq;
|
|
|
|
wcstring mode;
|
|
|
|
};
|
|
|
|
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
2014-09-23 12:04:06 +08:00
|
|
|
Returns all mapping names and modes
|
2008-01-14 00:47:47 +08:00
|
|
|
*/
|
2014-09-23 12:04:06 +08:00
|
|
|
std::vector<input_mapping_name_t> input_mapping_get_names();
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
|
|
|
Erase binding for specified key sequence
|
|
|
|
*/
|
2014-09-23 12:04:06 +08:00
|
|
|
bool input_mapping_erase(const wcstring &sequence, const wcstring &mode = DEFAULT_BIND_MODE);
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2008-01-14 00:47:47 +08:00
|
|
|
/**
|
2014-09-23 12:04:06 +08:00
|
|
|
Gets the command bound to the specified key sequence in the specified mode. Returns true if it exists, false if not.
|
2008-01-14 00:47:47 +08:00
|
|
|
*/
|
2014-09-23 12:04:06 +08:00
|
|
|
bool input_mapping_get(const wcstring &sequence, const wcstring &mode, wcstring_list_t *out_cmds, wcstring *out_new_mode);
|
2013-12-31 08:52:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the current bind mode
|
|
|
|
*/
|
2014-03-31 04:13:35 +08:00
|
|
|
wcstring input_get_bind_mode();
|
2013-12-31 08:52:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the current bind mode
|
|
|
|
*/
|
2014-03-31 04:13:35 +08:00
|
|
|
void input_set_bind_mode(const wcstring &bind_mode);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2014-01-22 17:00:44 +08:00
|
|
|
|
|
|
|
wchar_t input_function_pop_arg();
|
|
|
|
|
2014-01-23 17:23:04 +08:00
|
|
|
|
2014-04-01 01:01:39 +08:00
|
|
|
/**
|
2014-01-23 17:23:04 +08:00
|
|
|
Sets the return status of the most recently executed input function
|
|
|
|
*/
|
|
|
|
void input_function_set_status(bool status);
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2007-09-26 00:14:47 +08:00
|
|
|
Return the sequence for the terminfo variable of the specified name.
|
|
|
|
|
2013-04-16 04:07:17 +08:00
|
|
|
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.
|
2007-09-26 00:14:47 +08:00
|
|
|
*/
|
2013-04-16 04:07:17 +08:00
|
|
|
bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2014-07-08 01:45:26 +08:00
|
|
|
/** Return the name of the terminfo variable with the specified sequence, in out_name. Returns true if found, false if not found. */
|
|
|
|
bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-08 09:06:45 +08:00
|
|
|
/** Return a list of all known terminfo names */
|
2012-11-19 08:30:30 +08:00
|
|
|
wcstring_list_t input_terminfo_get_names(bool skip_null);
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2012-03-06 06:18:16 +08:00
|
|
|
/** Returns the input function code for the given input function name. */
|
2012-11-19 08:30:30 +08:00
|
|
|
wchar_t input_function_get_code(const wcstring &name);
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2012-03-06 06:18:16 +08:00
|
|
|
/** Returns a list of all existing input function names */
|
2012-11-19 08:30:30 +08:00
|
|
|
wcstring_list_t input_function_get_names(void);
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2014-09-20 06:37:31 +08:00
|
|
|
/** Updates our idea of whether we support term256 and term24bit */
|
|
|
|
void update_fish_color_support();
|
2012-03-06 06:18:16 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|