Better input handling; add support multiple binding commands

This commit is contained in:
Julian Aron Prenner
2014-01-01 00:11:32 +01:00
parent f408bc4808
commit dc90cd6bc4
4 changed files with 143 additions and 131 deletions

View File

@@ -413,27 +413,38 @@ static void builtin_bind_list(const wchar_t *bind_mode)
{
wcstring seq = lst.at(i);
wcstring ecmd;
std::vector<wcstring> ecmds;
wcstring mode;
wcstring new_mode;
input_mapping_get(seq, ecmd, mode);
input_mapping_get(seq, ecmds, mode, new_mode);
if(bind_mode != NULL && wcscmp(mode.c_str(), bind_mode))
{
continue;
}
ecmd = escape_string(ecmd, 1);
wcstring tname;
if (input_terminfo_get_name(seq, tname))
{
append_format(stdout_buffer, L"bind -k %ls %ls (in mode `%ls')\n", tname.c_str(), ecmd.c_str(), mode.c_str());
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", tname.c_str(), mode.c_str(), new_mode.c_str());
for(int i = 0; i < ecmds.size(); i++)
{
wcstring ecmd = ecmds.at(i);
append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
}
append_format(stdout_buffer, L"\n");
}
else
{
const wcstring eseq = escape_string(seq, 1);
append_format(stdout_buffer, L"bind %ls %ls (in mode `%ls')\n", eseq.c_str(), ecmd.c_str(), mode.c_str());
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), new_mode.c_str());
for(int i = 0; i < ecmds.size(); i++)
{
wcstring ecmd = ecmds.at(i);
append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
}
append_format(stdout_buffer, L"\n");
}
}
}
@@ -474,7 +485,8 @@ static void builtin_bind_function_names()
/**
Add specified key binding.
*/
static int builtin_bind_add(const wchar_t *seq, const wchar_t *cmd, const wchar_t *mode, const wchar_t *new_mode, int terminfo)
static int builtin_bind_add(const wchar_t *seq, const wchar_t **cmds, size_t cmds_len,
const wchar_t *mode, const wchar_t *new_mode, int terminfo)
{
if (terminfo)
@@ -482,7 +494,7 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t *cmd, const wchar_
wcstring seq2;
if (input_terminfo_get_sequence(seq, &seq2))
{
input_mapping_add(seq2.c_str(), cmd, mode, new_mode);
input_mapping_add(seq2.c_str(), cmds, cmds_len, mode, new_mode);
}
else
{
@@ -515,7 +527,7 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t *cmd, const wchar_
}
else
{
input_mapping_add(seq, cmd, mode, new_mode);
input_mapping_add(seq, cmds, cmds_len, mode, new_mode);
}
return 0;
@@ -718,18 +730,19 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
break;
}
case 2:
case 1:
{
builtin_bind_add(argv[woptind], argv[woptind+1], bind_mode, new_bind_mode, use_terminfo);
res = STATUS_BUILTIN_ERROR;
append_format(stderr_buffer, _(L"%ls: Expected zero or at least two parameters, got %d"), argv[0], argc-woptind);
break;
}
default:
{
res = STATUS_BUILTIN_ERROR;
append_format(stderr_buffer, _(L"%ls: Expected zero or two parameters, got %d"), argv[0], argc-woptind);
builtin_bind_add(argv[woptind], (const wchar_t **)argv + (woptind + 1), argc - (woptind + 1), bind_mode, new_bind_mode, use_terminfo);
break;
}
}
break;
}