diff options
author | 2014-01-01 00:11:32 +0100 | |
---|---|---|
committer | 2014-01-01 00:11:32 +0100 | |
commit | dc90cd6bc4fdbb7b2b0a893cf40256f50b11c012 (patch) | |
tree | 9a4047997d691cfae6a32f458361782041e38614 /builtin.cpp | |
parent | f408bc4808c592afce93e877e587c8c98a590dd9 (diff) |
Better input handling; add support multiple binding commands
Diffstat (limited to 'builtin.cpp')
-rw-r--r-- | builtin.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/builtin.cpp b/builtin.cpp index 335b81ce..0d7ed222 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -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; } |