2005-09-20 13:26:39 +00:00
|
|
|
/** \file input.c
|
2007-09-21 14:07:52 +00:00
|
|
|
|
2007-10-02 09:28:38 +00:00
|
|
|
Functions for reading a character of input from stdin.
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-01-14 10:42:17 +00:00
|
|
|
#include <assert.h>
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2006-08-09 22:53:38 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TERMIOS_H
|
|
|
|
#include <sys/termios.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <sys/ioctl.h>
|
2006-08-09 22:53:38 +00:00
|
|
|
#endif
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#if HAVE_NCURSES_H
|
|
|
|
#include <ncurses.h>
|
|
|
|
#else
|
|
|
|
#include <curses.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if HAVE_TERMIO_H
|
|
|
|
#include <termio.h>
|
|
|
|
#endif
|
|
|
|
|
2006-01-19 12:22:07 +00:00
|
|
|
#if HAVE_TERM_H
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <term.h>
|
2006-01-19 12:22:07 +00:00
|
|
|
#elif HAVE_NCURSES_TERM_H
|
|
|
|
#include <ncurses/term.h>
|
|
|
|
#endif
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <wctype.h>
|
|
|
|
|
|
|
|
|
2006-02-28 13:17:16 +00:00
|
|
|
|
|
|
|
#include "fallback.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "util.h"
|
2006-02-28 13:17:16 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "wutil.h"
|
|
|
|
#include "reader.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "sanity.h"
|
|
|
|
#include "input_common.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "env.h"
|
|
|
|
#include "expand.h"
|
2005-11-25 14:18:26 +00:00
|
|
|
#include "event.h"
|
2006-02-09 15:50:20 +00:00
|
|
|
#include "signal.h"
|
2006-07-19 22:55:49 +00:00
|
|
|
|
2006-02-16 13:40:25 +00:00
|
|
|
#include "output.h"
|
2006-06-21 14:03:44 +00:00
|
|
|
#include "intern.h"
|
2012-02-08 07:15:32 +00:00
|
|
|
#include <vector>
|
2007-09-25 16:14:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Struct representing a keybinding. Returned by input_get_mappings.
|
|
|
|
*/
|
2011-12-31 23:57:30 +00:00
|
|
|
struct input_mapping_t
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
wcstring seq; /**< Character sequence which generates this event */
|
|
|
|
wcstring command; /**< command that should be evaluated by this mapping */
|
|
|
|
|
|
|
|
|
|
|
|
input_mapping_t(const wcstring &s, const wcstring &c) : seq(s), command(c) {}
|
|
|
|
};
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-02 13:40:46 +00:00
|
|
|
/**
|
2007-09-25 16:14:47 +00:00
|
|
|
A struct representing the mapping from a terminfo key name to a terminfo character sequence
|
|
|
|
*/
|
2012-02-08 07:15:32 +00:00
|
|
|
struct terminfo_mapping_t
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
|
|
|
const wchar_t *name; /**< Name of key */
|
2012-02-08 07:15:32 +00:00
|
|
|
const char *seq; /**< Character sequence generated on keypress. Constant string. */
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
};
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2005-10-02 13:40:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2007-10-02 09:28:38 +00:00
|
|
|
Names of all the input functions supported
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
static const wchar_t *name_arr[] =
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
|
|
|
L"beginning-of-line",
|
|
|
|
L"end-of-line",
|
|
|
|
L"forward-char",
|
|
|
|
L"backward-char",
|
|
|
|
L"forward-word",
|
|
|
|
L"backward-word",
|
|
|
|
L"history-search-backward",
|
|
|
|
L"history-search-forward",
|
|
|
|
L"delete-char",
|
|
|
|
L"backward-delete-char",
|
|
|
|
L"kill-line",
|
|
|
|
L"yank",
|
|
|
|
L"yank-pop",
|
|
|
|
L"complete",
|
|
|
|
L"beginning-of-history",
|
|
|
|
L"end-of-history",
|
|
|
|
L"backward-kill-line",
|
|
|
|
L"kill-whole-line",
|
|
|
|
L"kill-word",
|
|
|
|
L"backward-kill-word",
|
|
|
|
L"dump-functions",
|
|
|
|
L"history-token-search-backward",
|
|
|
|
L"history-token-search-forward",
|
|
|
|
L"self-insert",
|
2006-05-14 10:16:23 +00:00
|
|
|
L"null",
|
2006-07-23 20:52:03 +00:00
|
|
|
L"eof",
|
2006-10-09 01:15:29 +00:00
|
|
|
L"vi-arg-digit",
|
2006-10-31 22:01:49 +00:00
|
|
|
L"execute",
|
|
|
|
L"beginning-of-buffer",
|
2006-12-12 10:13:48 +00:00
|
|
|
L"end-of-buffer",
|
2007-09-21 14:05:49 +00:00
|
|
|
L"repaint",
|
|
|
|
L"up-line",
|
|
|
|
L"down-line"
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
2007-10-02 09:28:38 +00:00
|
|
|
Description of each supported input function
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2006-06-13 17:23:37 +00:00
|
|
|
/*
|
|
|
|
static const wchar_t *desc_arr[] =
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
|
|
|
L"Move to beginning of line",
|
|
|
|
L"Move to end of line",
|
|
|
|
L"Move forward one character",
|
|
|
|
L"Move backward one character",
|
|
|
|
L"Move forward one word",
|
|
|
|
L"Move backward one word",
|
|
|
|
L"Search backward through list of previous commands",
|
|
|
|
L"Search forward through list of previous commands",
|
|
|
|
L"Delete one character forward",
|
|
|
|
L"Delete one character backward",
|
|
|
|
L"Move contents from cursor to end of line to killring",
|
|
|
|
L"Paste contents of killring",
|
|
|
|
L"Rotate to previous killring entry",
|
|
|
|
L"Guess the rest of the next input token",
|
|
|
|
L"Move to first item of history",
|
|
|
|
L"Move to last item of history",
|
|
|
|
L"Clear current line",
|
|
|
|
L"Move contents from beginning of line to cursor to killring",
|
|
|
|
L"Move entire line to killring",
|
|
|
|
L"Move next word to killring",
|
|
|
|
L"Move previous word to killring",
|
|
|
|
L"Write out keybindings",
|
|
|
|
L"Clear entire screen",
|
|
|
|
L"Quit the running program",
|
|
|
|
L"Search backward through list of previous commands for matching token",
|
|
|
|
L"Search forward through list of previous commands for matching token",
|
|
|
|
L"Insert the pressed key",
|
2006-05-14 10:16:23 +00:00
|
|
|
L"Do nothing",
|
2006-07-23 20:52:03 +00:00
|
|
|
L"End of file",
|
|
|
|
L"Repeat command"
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
;
|
2006-06-13 17:23:37 +00:00
|
|
|
*/
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2007-10-02 09:28:38 +00:00
|
|
|
Internal code for each supported input function
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
static const wchar_t code_arr[] =
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
|
|
|
R_BEGINNING_OF_LINE,
|
|
|
|
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,
|
|
|
|
R_DUMP_FUNCTIONS,
|
|
|
|
R_HISTORY_TOKEN_SEARCH_BACKWARD,
|
|
|
|
R_HISTORY_TOKEN_SEARCH_FORWARD,
|
|
|
|
R_SELF_INSERT,
|
2006-05-14 10:16:23 +00:00
|
|
|
R_NULL,
|
2006-07-23 20:52:03 +00:00
|
|
|
R_EOF,
|
2006-10-09 01:15:29 +00:00
|
|
|
R_VI_ARG_DIGIT,
|
2006-10-31 22:01:49 +00:00
|
|
|
R_EXECUTE,
|
|
|
|
R_BEGINNING_OF_BUFFER,
|
|
|
|
R_END_OF_BUFFER,
|
2007-09-21 14:05:49 +00:00
|
|
|
R_REPAINT,
|
|
|
|
R_UP_LINE,
|
|
|
|
R_DOWN_LINE
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
/** Mappings for the current input mode */
|
|
|
|
static std::vector<input_mapping_t> mapping_list;
|
|
|
|
|
|
|
|
/* Terminfo map list */
|
|
|
|
static std::vector<terminfo_mapping_t> terminfo_mappings;
|
|
|
|
|
|
|
|
/** Add a new terminfo mapping */
|
|
|
|
static inline void terminfo_add(const wchar_t *name, const char *seq)
|
|
|
|
{
|
|
|
|
terminfo_mapping_t mapping = {name, seq};
|
|
|
|
terminfo_mappings.push_back(mapping);
|
|
|
|
}
|
|
|
|
#define TERMINFO_ADD(key) do { terminfo_add((L ## #key)+4, key); } while (0)
|
|
|
|
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
|
|
|
List of all terminfo mappings
|
|
|
|
*/
|
2012-02-08 07:15:32 +00:00
|
|
|
static std::vector<terminfo_mapping_t> mappings;
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
|
2006-06-20 00:50:10 +00:00
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
Set to one when the input subsytem has been initialized.
|
2006-06-20 00:50:10 +00:00
|
|
|
*/
|
2006-03-10 13:38:09 +00:00
|
|
|
static int is_init = 0;
|
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
|
|
|
Initialize terminfo.
|
|
|
|
*/
|
2007-09-25 16:14:47 +00:00
|
|
|
static void input_terminfo_init();
|
2012-02-08 07:15:32 +00:00
|
|
|
|
2006-07-23 20:52:03 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Returns the function description for the given function code.
|
|
|
|
*/
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
void input_mapping_add( const wchar_t *sequence,
|
|
|
|
const wchar_t *command )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
size_t i;
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
CHECK( sequence, );
|
|
|
|
CHECK( command, );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
// debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
for( i=0; i<mapping_list.size(); i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
input_mapping_t &m = mapping_list.at(i);
|
|
|
|
if( m.seq == sequence )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
m.command = command;
|
2005-09-20 13:26:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-12-31 23:57:30 +00:00
|
|
|
mapping_list.push_back(input_mapping_t(sequence, command));
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-25 16:14:47 +00:00
|
|
|
Handle interruptions to key reading by reaping finshed jobs and
|
|
|
|
propagating the interrupt to the reader.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2007-09-25 16:14:47 +00:00
|
|
|
static int interrupt_handler()
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
Fire any pending events
|
|
|
|
*/
|
2010-09-18 13:30:02 +00:00
|
|
|
event_fire( NULL );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
Reap stray processes, including printing exit status messages
|
|
|
|
*/
|
|
|
|
if( job_reap( 1 ) )
|
2007-10-05 14:59:19 +00:00
|
|
|
reader_repaint_needed();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
Tell the reader an event occured
|
|
|
|
*/
|
|
|
|
if( reader_interrupted() )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Return 3, i.e. the character read by a Control-C.
|
|
|
|
*/
|
|
|
|
return 3;
|
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2011-12-27 03:18:46 +00:00
|
|
|
return R_NULL;
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
void update_fish_term256(void)
|
|
|
|
{
|
2012-03-06 22:32:00 +00:00
|
|
|
/* Infer term256 support. If fish_term256 is set, we respect it; otherwise try to detect it from the TERM variable */
|
2012-03-05 22:18:16 +00:00
|
|
|
env_var_t fish_term256 = env_get_string(L"fish_term256");
|
|
|
|
bool support_term256;
|
|
|
|
if (! fish_term256.missing_or_empty()) {
|
|
|
|
support_term256 = from_string<bool>(fish_term256);
|
|
|
|
} else {
|
|
|
|
env_var_t term = env_get_string(L"TERM");
|
2012-04-01 07:53:47 +00:00
|
|
|
if (term.missing()) {
|
|
|
|
support_term256 = false;
|
|
|
|
} else {
|
|
|
|
// assume that all xterms are 256
|
|
|
|
support_term256 = (term.find(L"256color") != wcstring::npos || term.find(L"xterm") != wcstring::npos);
|
|
|
|
}
|
2012-03-05 22:18:16 +00:00
|
|
|
}
|
|
|
|
output_set_supports_term256(support_term256);
|
|
|
|
}
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
int input_init()
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
if( is_init )
|
|
|
|
return 1;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
is_init = 1;
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
input_common_init( &interrupt_handler );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
if( setupterm( 0, STDOUT_FILENO, 0) == ERR )
|
|
|
|
{
|
|
|
|
debug( 0, _( L"Could not set up terminal" ) );
|
2012-02-28 23:11:46 +00:00
|
|
|
exit_without_destructors(1);
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2012-01-14 10:42:17 +00:00
|
|
|
const env_var_t term = env_get_string( L"TERM" );
|
|
|
|
assert(! term.missing());
|
|
|
|
output_set_term( term.c_str() );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
input_terminfo_init();
|
2012-03-05 18:44:08 +00:00
|
|
|
|
2012-03-05 22:18:16 +00:00
|
|
|
update_fish_term256();
|
2012-03-05 18:44:08 +00:00
|
|
|
|
|
|
|
/* If we have no keybindings, add a few simple defaults */
|
2011-12-31 23:57:30 +00:00
|
|
|
if( mapping_list.size() )
|
2007-10-15 08:51:30 +00:00
|
|
|
{
|
|
|
|
input_mapping_add( L"", L"self-insert" );
|
|
|
|
input_mapping_add( L"\n", L"execute" );
|
|
|
|
input_mapping_add( L"\t", L"complete" );
|
|
|
|
input_mapping_add( L"\x3", L"commandline \"\"" );
|
|
|
|
input_mapping_add( L"\x4", L"exit" );
|
|
|
|
input_mapping_add( L"\x5", L"bind" );
|
|
|
|
}
|
2005-10-02 13:40:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2005-10-02 13:40:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
void input_destroy()
|
2005-10-02 13:40:46 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
if( !is_init )
|
|
|
|
return;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-10-02 13:40:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
is_init=0;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
input_common_destroy();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
if( del_curterm( cur_term ) == ERR )
|
2005-10-02 13:40:46 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
debug( 0, _(L"Error while closing terminfo") );
|
2005-10-02 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2007-09-25 16:14:47 +00:00
|
|
|
Perform the action of the specified binding
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2011-12-31 23:57:30 +00:00
|
|
|
static wint_t input_exec_binding( const input_mapping_t &m, const wcstring &seq )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
wchar_t code = input_function_get_code( m.command );
|
2007-09-25 16:14:47 +00:00
|
|
|
if( code != -1 )
|
2011-12-27 03:18:46 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
switch( code )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2005-09-25 22:39:48 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
case R_SELF_INSERT:
|
|
|
|
{
|
|
|
|
return seq[0];
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
default:
|
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
return code;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
This key sequence is bound to a command, which
|
|
|
|
is sent to the parser for evaluation.
|
|
|
|
*/
|
2008-01-08 19:31:45 +00:00
|
|
|
int last_status = proc_get_last_status();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-01-23 05:40:08 +00:00
|
|
|
parser_t::principal_parser().eval( m.command.c_str(), 0, TOP );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2008-01-08 19:31:45 +00:00
|
|
|
proc_set_last_status( last_status );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
We still need to return something to the caller, R_NULL
|
2011-12-27 03:18:46 +00:00
|
|
|
tells the reader that no key press needs to be handled,
|
2007-09-25 16:14:47 +00:00
|
|
|
and no repaint is needed.
|
|
|
|
|
|
|
|
Bindings that produce output should emit a R_REPAINT
|
|
|
|
function by calling 'commandline -f repaint' to tell
|
2011-12-27 03:18:46 +00:00
|
|
|
fish that a repaint is in order.
|
2007-09-25 16:14:47 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
return R_NULL;
|
2005-09-25 22:39:48 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/**
|
|
|
|
Try reading the specified function mapping
|
|
|
|
*/
|
2011-12-31 23:57:30 +00:00
|
|
|
static wint_t input_try_mapping( const input_mapping_t &m)
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
|
|
|
int j, k;
|
|
|
|
wint_t c=0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if the actual function code of this mapping is on the stack
|
|
|
|
*/
|
|
|
|
c = input_common_readch( 0 );
|
2011-12-31 23:57:30 +00:00
|
|
|
if( c == input_function_get_code( m.command ) )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
return input_exec_binding( m, m.seq );
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2007-09-25 16:14:47 +00:00
|
|
|
input_unreadch( c );
|
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
const wchar_t *str = m.seq.c_str();
|
2012-03-04 04:38:16 +00:00
|
|
|
for( j=0; str[j] != L'\0' && str[j] == (c=input_common_readch( j>0 )); j++ )
|
2011-12-31 23:57:30 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
if( str[j] == L'\0' )
|
|
|
|
{
|
|
|
|
return input_exec_binding( m, m.seq );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Return the read characters
|
|
|
|
*/
|
|
|
|
input_unreadch(c);
|
|
|
|
for( k=j-1; k>=0; k-- )
|
|
|
|
{
|
|
|
|
input_unreadch( m.seq[k] );
|
|
|
|
}
|
|
|
|
}
|
2007-09-25 16:14:47 +00:00
|
|
|
return 0;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
void input_unreadch( wint_t ch )
|
|
|
|
{
|
|
|
|
input_common_unreadch( ch );
|
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
wint_t input_readch()
|
|
|
|
{
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
size_t i;
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
CHECK_BLOCK( R_NULL );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
|
|
|
Clear the interrupted flag
|
|
|
|
*/
|
|
|
|
reader_interrupted();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
2007-10-02 09:28:38 +00:00
|
|
|
Search for sequence in mapping tables
|
2007-09-25 16:14:47 +00:00
|
|
|
*/
|
2007-10-15 08:51:30 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
while( 1 )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
const input_mapping_t *generic = 0;
|
|
|
|
for( i=0; i<mapping_list.size(); i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
const input_mapping_t &m = mapping_list.at(i);
|
2011-12-27 03:18:46 +00:00
|
|
|
wint_t res = input_try_mapping( m );
|
2007-09-25 16:14:47 +00:00
|
|
|
if( res )
|
2007-10-02 09:28:38 +00:00
|
|
|
return res;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
if( m.seq.length() == 0 )
|
2007-10-02 09:28:38 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
generic = &m;
|
2007-10-02 09:28:38 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-10-02 13:40:46 +00:00
|
|
|
/*
|
2007-09-25 16:14:47 +00:00
|
|
|
No matching exact mapping, try to find generic mapping.
|
2005-10-02 13:40:46 +00:00
|
|
|
*/
|
2007-10-02 09:28:38 +00:00
|
|
|
|
|
|
|
if( generic )
|
2011-12-27 03:18:46 +00:00
|
|
|
{
|
2007-10-02 09:28:38 +00:00
|
|
|
wchar_t arr[2]=
|
|
|
|
{
|
2011-12-27 03:18:46 +00:00
|
|
|
0,
|
2007-10-02 09:28:38 +00:00
|
|
|
0
|
|
|
|
}
|
|
|
|
;
|
|
|
|
arr[0] = input_common_readch(0);
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
return input_exec_binding( *generic, arr );
|
2005-10-02 13:40:46 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
/*
|
2007-10-02 09:28:38 +00:00
|
|
|
No action to take on specified character, ignore it
|
2007-09-25 16:14:47 +00:00
|
|
|
and move to next one.
|
2007-10-15 08:51:30 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
input_common_readch( 0 ); }
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
void input_mapping_get_names( wcstring_list_t &lst )
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
size_t i;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
for( i=0; i<mapping_list.size(); i++ )
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
const input_mapping_t &m = mapping_list.at(i);
|
|
|
|
lst.push_back(wcstring(m.seq));
|
2005-10-02 13:40:46 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
bool input_mapping_erase( const wchar_t *sequence )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
ASSERT_IS_MAIN_THREAD();
|
|
|
|
bool result = false;
|
|
|
|
size_t i, sz = mapping_list.size();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
for( i=0; i<sz; i++ )
|
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
const input_mapping_t &m = mapping_list.at(i);
|
|
|
|
if( sequence == m.seq )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
if( i != (sz-1 ) )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
mapping_list[i] = mapping_list[sz-1];
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-31 23:57:30 +00:00
|
|
|
mapping_list.pop_back();
|
|
|
|
result = true;
|
2007-09-25 16:14:47 +00:00
|
|
|
break;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-31 23:57:30 +00:00
|
|
|
return result;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
bool input_mapping_get( const wcstring &sequence, wcstring &cmd )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
size_t i, sz = mapping_list.size();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
for( i=0; i<sz; i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
const input_mapping_t &m = mapping_list.at(i);
|
|
|
|
if( sequence == m.seq )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
cmd = m.command;
|
|
|
|
return true;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-31 23:57:30 +00:00
|
|
|
return false;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2007-09-28 21:32:27 +00:00
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
/**
|
2007-09-25 16:14:47 +00:00
|
|
|
Add all terminfo mappings
|
|
|
|
*/
|
|
|
|
static void input_terminfo_init()
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-28 21:36:16 +00:00
|
|
|
TERMINFO_ADD(key_a1);
|
|
|
|
TERMINFO_ADD(key_a3);
|
|
|
|
TERMINFO_ADD(key_b2);
|
|
|
|
TERMINFO_ADD(key_backspace);
|
|
|
|
TERMINFO_ADD(key_beg);
|
|
|
|
TERMINFO_ADD(key_btab);
|
|
|
|
TERMINFO_ADD(key_c1);
|
|
|
|
TERMINFO_ADD(key_c3);
|
|
|
|
TERMINFO_ADD(key_cancel);
|
|
|
|
TERMINFO_ADD(key_catab);
|
|
|
|
TERMINFO_ADD(key_clear);
|
|
|
|
TERMINFO_ADD(key_close);
|
|
|
|
TERMINFO_ADD(key_command);
|
|
|
|
TERMINFO_ADD(key_copy);
|
|
|
|
TERMINFO_ADD(key_create);
|
|
|
|
TERMINFO_ADD(key_ctab);
|
|
|
|
TERMINFO_ADD(key_dc);
|
|
|
|
TERMINFO_ADD(key_dl);
|
|
|
|
TERMINFO_ADD(key_down);
|
|
|
|
TERMINFO_ADD(key_eic);
|
|
|
|
TERMINFO_ADD(key_end);
|
|
|
|
TERMINFO_ADD(key_enter);
|
|
|
|
TERMINFO_ADD(key_eol);
|
|
|
|
TERMINFO_ADD(key_eos);
|
|
|
|
TERMINFO_ADD(key_exit);
|
|
|
|
TERMINFO_ADD(key_f0);
|
|
|
|
TERMINFO_ADD(key_f1);
|
|
|
|
TERMINFO_ADD(key_f2);
|
|
|
|
TERMINFO_ADD(key_f3);
|
|
|
|
TERMINFO_ADD(key_f4);
|
|
|
|
TERMINFO_ADD(key_f5);
|
|
|
|
TERMINFO_ADD(key_f6);
|
|
|
|
TERMINFO_ADD(key_f7);
|
|
|
|
TERMINFO_ADD(key_f8);
|
|
|
|
TERMINFO_ADD(key_f9);
|
|
|
|
TERMINFO_ADD(key_f10);
|
|
|
|
TERMINFO_ADD(key_f11);
|
|
|
|
TERMINFO_ADD(key_f12);
|
|
|
|
TERMINFO_ADD(key_f13);
|
|
|
|
TERMINFO_ADD(key_f14);
|
|
|
|
TERMINFO_ADD(key_f15);
|
|
|
|
TERMINFO_ADD(key_f16);
|
|
|
|
TERMINFO_ADD(key_f17);
|
|
|
|
TERMINFO_ADD(key_f18);
|
|
|
|
TERMINFO_ADD(key_f19);
|
|
|
|
TERMINFO_ADD(key_f20);
|
2007-10-02 09:28:38 +00:00
|
|
|
/*
|
2007-10-02 10:09:37 +00:00
|
|
|
I know of no keyboard with more than 20 function keys, so
|
|
|
|
adding the rest here makes very little sense, since it will
|
|
|
|
take up a lot of room in any listings (like tab completions),
|
|
|
|
but with no benefit.
|
2007-10-02 09:28:38 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
TERMINFO_ADD(key_f21);
|
2007-09-28 21:36:16 +00:00
|
|
|
TERMINFO_ADD(key_f22);
|
|
|
|
TERMINFO_ADD(key_f23);
|
|
|
|
TERMINFO_ADD(key_f24);
|
|
|
|
TERMINFO_ADD(key_f25);
|
|
|
|
TERMINFO_ADD(key_f26);
|
|
|
|
TERMINFO_ADD(key_f27);
|
|
|
|
TERMINFO_ADD(key_f28);
|
|
|
|
TERMINFO_ADD(key_f29);
|
|
|
|
TERMINFO_ADD(key_f30);
|
|
|
|
TERMINFO_ADD(key_f31);
|
|
|
|
TERMINFO_ADD(key_f32);
|
|
|
|
TERMINFO_ADD(key_f33);
|
|
|
|
TERMINFO_ADD(key_f34);
|
|
|
|
TERMINFO_ADD(key_f35);
|
|
|
|
TERMINFO_ADD(key_f36);
|
|
|
|
TERMINFO_ADD(key_f37);
|
|
|
|
TERMINFO_ADD(key_f38);
|
|
|
|
TERMINFO_ADD(key_f39);
|
|
|
|
TERMINFO_ADD(key_f40);
|
|
|
|
TERMINFO_ADD(key_f41);
|
|
|
|
TERMINFO_ADD(key_f42);
|
|
|
|
TERMINFO_ADD(key_f43);
|
|
|
|
TERMINFO_ADD(key_f44);
|
|
|
|
TERMINFO_ADD(key_f45);
|
|
|
|
TERMINFO_ADD(key_f46);
|
|
|
|
TERMINFO_ADD(key_f47);
|
|
|
|
TERMINFO_ADD(key_f48);
|
|
|
|
TERMINFO_ADD(key_f49);
|
|
|
|
TERMINFO_ADD(key_f50);
|
|
|
|
TERMINFO_ADD(key_f51);
|
|
|
|
TERMINFO_ADD(key_f52);
|
|
|
|
TERMINFO_ADD(key_f53);
|
|
|
|
TERMINFO_ADD(key_f54);
|
|
|
|
TERMINFO_ADD(key_f55);
|
|
|
|
TERMINFO_ADD(key_f56);
|
|
|
|
TERMINFO_ADD(key_f57);
|
|
|
|
TERMINFO_ADD(key_f58);
|
|
|
|
TERMINFO_ADD(key_f59);
|
|
|
|
TERMINFO_ADD(key_f60);
|
|
|
|
TERMINFO_ADD(key_f61);
|
|
|
|
TERMINFO_ADD(key_f62);
|
|
|
|
TERMINFO_ADD(key_f63);*/
|
|
|
|
TERMINFO_ADD(key_find);
|
|
|
|
TERMINFO_ADD(key_help);
|
|
|
|
TERMINFO_ADD(key_home);
|
|
|
|
TERMINFO_ADD(key_ic);
|
|
|
|
TERMINFO_ADD(key_il);
|
|
|
|
TERMINFO_ADD(key_left);
|
|
|
|
TERMINFO_ADD(key_ll);
|
|
|
|
TERMINFO_ADD(key_mark);
|
|
|
|
TERMINFO_ADD(key_message);
|
|
|
|
TERMINFO_ADD(key_move);
|
|
|
|
TERMINFO_ADD(key_next);
|
|
|
|
TERMINFO_ADD(key_npage);
|
|
|
|
TERMINFO_ADD(key_open);
|
|
|
|
TERMINFO_ADD(key_options);
|
|
|
|
TERMINFO_ADD(key_ppage);
|
|
|
|
TERMINFO_ADD(key_previous);
|
|
|
|
TERMINFO_ADD(key_print);
|
|
|
|
TERMINFO_ADD(key_redo);
|
|
|
|
TERMINFO_ADD(key_reference);
|
|
|
|
TERMINFO_ADD(key_refresh);
|
|
|
|
TERMINFO_ADD(key_replace);
|
|
|
|
TERMINFO_ADD(key_restart);
|
|
|
|
TERMINFO_ADD(key_resume);
|
|
|
|
TERMINFO_ADD(key_right);
|
|
|
|
TERMINFO_ADD(key_save);
|
|
|
|
TERMINFO_ADD(key_sbeg);
|
|
|
|
TERMINFO_ADD(key_scancel);
|
|
|
|
TERMINFO_ADD(key_scommand);
|
|
|
|
TERMINFO_ADD(key_scopy);
|
|
|
|
TERMINFO_ADD(key_screate);
|
|
|
|
TERMINFO_ADD(key_sdc);
|
|
|
|
TERMINFO_ADD(key_sdl);
|
|
|
|
TERMINFO_ADD(key_select);
|
|
|
|
TERMINFO_ADD(key_send);
|
|
|
|
TERMINFO_ADD(key_seol);
|
|
|
|
TERMINFO_ADD(key_sexit);
|
|
|
|
TERMINFO_ADD(key_sf);
|
|
|
|
TERMINFO_ADD(key_sfind);
|
|
|
|
TERMINFO_ADD(key_shelp);
|
|
|
|
TERMINFO_ADD(key_shome);
|
|
|
|
TERMINFO_ADD(key_sic);
|
|
|
|
TERMINFO_ADD(key_sleft);
|
|
|
|
TERMINFO_ADD(key_smessage);
|
|
|
|
TERMINFO_ADD(key_smove);
|
|
|
|
TERMINFO_ADD(key_snext);
|
|
|
|
TERMINFO_ADD(key_soptions);
|
|
|
|
TERMINFO_ADD(key_sprevious);
|
|
|
|
TERMINFO_ADD(key_sprint);
|
|
|
|
TERMINFO_ADD(key_sr);
|
|
|
|
TERMINFO_ADD(key_sredo);
|
|
|
|
TERMINFO_ADD(key_sreplace);
|
|
|
|
TERMINFO_ADD(key_sright);
|
|
|
|
TERMINFO_ADD(key_srsume);
|
|
|
|
TERMINFO_ADD(key_ssave);
|
|
|
|
TERMINFO_ADD(key_ssuspend);
|
|
|
|
TERMINFO_ADD(key_stab);
|
|
|
|
TERMINFO_ADD(key_sundo);
|
|
|
|
TERMINFO_ADD(key_suspend);
|
|
|
|
TERMINFO_ADD(key_undo);
|
|
|
|
TERMINFO_ADD(key_up);
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
const wchar_t *input_terminfo_get_sequence( const wchar_t *name )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-02-08 07:17:20 +00:00
|
|
|
ASSERT_IS_MAIN_THREAD();
|
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
const char *res = 0;
|
2012-02-08 07:17:20 +00:00
|
|
|
static wcstring buff;
|
2007-09-25 16:14:47 +00:00
|
|
|
int err = ENOENT;
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
CHECK( name, 0 );
|
|
|
|
input_init();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
for( size_t i=0; i<terminfo_mappings.size(); i++ )
|
2006-01-18 12:42:48 +00:00
|
|
|
{
|
2012-02-08 07:15:32 +00:00
|
|
|
const terminfo_mapping_t &m = terminfo_mappings.at(i);
|
|
|
|
if( !wcscmp( name, m.name ) )
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
2012-02-08 07:15:32 +00:00
|
|
|
res = m.seq;
|
2007-09-25 16:14:47 +00:00
|
|
|
err = EILSEQ;
|
|
|
|
break;
|
|
|
|
}
|
2006-01-18 12:42:48 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
if( !res )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
errno = err;
|
|
|
|
return 0;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:17:20 +00:00
|
|
|
buff = format_string(L"%s", res);
|
|
|
|
return buff.c_str();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
bool input_terminfo_get_name( const wcstring &seq, wcstring &name )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
input_init();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
for( size_t i=0; i<terminfo_mappings.size(); i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-02-08 07:15:32 +00:00
|
|
|
terminfo_mapping_t &m = terminfo_mappings.at(i);
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
if( !m.seq )
|
2007-09-25 16:14:47 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
const wcstring map_buf = format_string(L"%s", m.seq);
|
2011-12-31 23:57:30 +00:00
|
|
|
if (map_buf == seq) {
|
2012-02-08 07:15:32 +00:00
|
|
|
name = m.name;
|
2011-12-31 23:57:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
return false;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 01:06:45 +00:00
|
|
|
wcstring_list_t input_terminfo_get_names( bool skip_null )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-02-08 01:06:45 +00:00
|
|
|
wcstring_list_t result;
|
2012-02-08 07:15:32 +00:00
|
|
|
result.reserve(terminfo_mappings.size());
|
2012-02-08 01:06:45 +00:00
|
|
|
|
2007-09-25 16:14:47 +00:00
|
|
|
input_init();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
for( size_t i=0; i<terminfo_mappings.size(); i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-02-08 07:15:32 +00:00
|
|
|
terminfo_mapping_t &m = terminfo_mappings.at(i);
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2012-02-08 07:15:32 +00:00
|
|
|
if( skip_null && !m.seq )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
continue;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2012-02-08 07:15:32 +00:00
|
|
|
result.push_back(wcstring(m.name));
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2012-02-08 01:06:45 +00:00
|
|
|
return result;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 04:48:47 +00:00
|
|
|
wcstring_list_t input_function_get_names( void )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-01-24 04:48:47 +00:00
|
|
|
size_t count = sizeof name_arr / sizeof *name_arr;
|
|
|
|
return wcstring_list_t(name_arr, name_arr + count);
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
wchar_t input_function_get_code( const wcstring &name )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2006-11-18 21:15:31 +00:00
|
|
|
|
2011-12-31 23:57:30 +00:00
|
|
|
size_t i;
|
2007-09-25 16:14:47 +00:00
|
|
|
for( i = 0; i<(sizeof( code_arr )/sizeof(wchar_t)) ; i++ )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2011-12-31 23:57:30 +00:00
|
|
|
if( name == name_arr[i] )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2007-09-25 16:14:47 +00:00
|
|
|
return code_arr[i];
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2007-09-25 16:14:47 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
return -1;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2007-09-25 16:14:47 +00:00
|
|
|
|