2005-09-20 13:26:39 +00:00
|
|
|
/** \file input.h
|
|
|
|
|
|
|
|
Functions for reading a character of input from stdin, using the
|
|
|
|
inputrc information for key bindings.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_INPUT_H
|
|
|
|
#define FISH_INPUT_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2006-03-10 13:38:09 +00:00
|
|
|
#include "input_common.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2013-12-31 00:52:41 +00:00
|
|
|
|
|
|
|
#define DEFAULT_BIND_MODE L"default"
|
2014-01-19 09:27:39 +00:00
|
|
|
#define FISH_BIND_MODE_VAR L"fish_bind_mode"
|
2013-12-31 00:52:41 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Key codes for inputrc-style keyboard functions that are passed on
|
|
|
|
to the caller of input_read()
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
2012-11-19 00:30:30 +00: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,
|
|
|
|
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 01:45:35 +00:00
|
|
|
R_BACKWARD_KILL_PATH_COMPONENT,
|
2012-11-19 00:30:30 +00:00
|
|
|
R_DUMP_FUNCTIONS,
|
|
|
|
R_HISTORY_TOKEN_SEARCH_BACKWARD,
|
|
|
|
R_HISTORY_TOKEN_SEARCH_FORWARD,
|
|
|
|
R_SELF_INSERT,
|
2013-05-20 19:42:34 +00:00
|
|
|
R_TRANSPOSE_CHARS,
|
2013-05-27 21:25:55 +00:00
|
|
|
R_TRANSPOSE_WORDS,
|
2013-09-09 16:46:16 +00:00
|
|
|
R_UPCASE_WORD,
|
|
|
|
R_DOWNCASE_WORD,
|
|
|
|
R_CAPITALIZE_WORD,
|
2012-11-19 00:30:30 +00:00
|
|
|
R_VI_ARG_DIGIT,
|
|
|
|
R_VI_DELETE_TO,
|
|
|
|
R_EXECUTE,
|
|
|
|
R_BEGINNING_OF_BUFFER,
|
|
|
|
R_END_OF_BUFFER,
|
|
|
|
R_REPAINT,
|
2013-12-31 13:53:29 +00:00
|
|
|
R_FORCE_REPAINT,
|
2012-11-19 00:30:30 +00:00
|
|
|
R_UP_LINE,
|
|
|
|
R_DOWN_LINE,
|
|
|
|
R_SUPPRESS_AUTOSUGGESTION,
|
2013-12-31 23:11:32 +00:00
|
|
|
R_ACCEPT_AUTOSUGGESTION,
|
2014-01-15 14:07:22 +00:00
|
|
|
R_BEGIN_SELECTION,
|
2014-01-18 09:18:29 +00:00
|
|
|
R_END_SELECTION,
|
|
|
|
R_KILL_SELECTION
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-12-31 23:11:32 +00:00
|
|
|
#define R_MIN R_NULL
|
2014-01-18 09:18:29 +00:00
|
|
|
#define R_MAX R_KILL_SELECTION
|
2013-12-31 23:11:32 +00:00
|
|
|
|
2005-09-20 13:26:39 +00: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.
|
|
|
|
*/
|
|
|
|
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
|
2012-11-18 10:23:22 +00:00
|
|
|
0.
|
2006-01-23 20:40:14 +00:00
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
void input_unreadch(wint_t ch);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-13 16:47:47 +00:00
|
|
|
Add a key mapping from the specified sequence to the specified command
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
\param sequence the sequence to bind
|
|
|
|
\param command an input function that will be run whenever the key sequence occurs
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2013-12-31 00:52:41 +00: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-25 16:14:47 +00:00
|
|
|
|
2013-12-31 23:11:32 +00: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);
|
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
2011-12-31 23:57:30 +00:00
|
|
|
Insert all mapping names into the specified wcstring_list_t
|
2008-01-13 16:47:47 +00:00
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
void input_mapping_get_names(wcstring_list_t &lst);
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
|
|
|
Erase binding for specified key sequence
|
|
|
|
*/
|
2013-12-31 00:52:41 +00:00
|
|
|
bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode = DEFAULT_BIND_MODE);
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
2011-12-31 23:57:30 +00:00
|
|
|
Gets the command bound to the specified key sequence. Returns true if it exists, false if not.
|
2008-01-13 16:47:47 +00:00
|
|
|
*/
|
2013-12-31 23:11:32 +00:00
|
|
|
bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wcstring &mode, wcstring &new_mode);
|
2013-12-31 00:52:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the current bind mode
|
|
|
|
*/
|
|
|
|
const wchar_t *input_get_bind_mode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the current bind mode
|
|
|
|
*/
|
|
|
|
bool input_set_bind_mode(const wchar_t *bind_mode);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2007-09-25 16:14:47 +00:00
|
|
|
Return the sequence for the terminfo variable of the specified name.
|
|
|
|
|
2013-04-15 20:07:17 +00: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-25 16:14:47 +00:00
|
|
|
*/
|
2013-04-15 20:07:17 +00:00
|
|
|
bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
/** Return the name of the terminfo variable with the specified sequence */
|
2012-11-19 00:30:30 +00:00
|
|
|
bool input_terminfo_get_name(const wcstring &seq, wcstring &name);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-02-08 01:06:45 +00:00
|
|
|
/** Return a list of all known terminfo names */
|
2012-11-19 00:30:30 +00:00
|
|
|
wcstring_list_t input_terminfo_get_names(bool skip_null);
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
/** Returns the input function code for the given input function name. */
|
2012-11-19 00:30:30 +00:00
|
|
|
wchar_t input_function_get_code(const wcstring &name);
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
/** Returns a list of all existing input function names */
|
2012-11-19 00:30:30 +00:00
|
|
|
wcstring_list_t input_function_get_names(void);
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
/** Updates our idea of whether we support term256 */
|
|
|
|
void update_fish_term256();
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|