bind should not show -k for bindings that are escape sequences, not keys

This commit is contained in:
ridiculousfish 2014-07-07 10:45:26 -07:00
parent d5fa4b2ccb
commit 3915faf382
3 changed files with 24 additions and 13 deletions

View file

@ -423,19 +423,30 @@ static void builtin_bind_list(const wchar_t *bind_mode)
{
continue;
}
// Append the initial 'bind' command and the name
wcstring tname;
const wcstring eseq = input_terminfo_get_name(seq, tname) ? tname : escape_string(seq, 1);
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), sets_mode.c_str());
if (input_terminfo_get_name(seq, &tname))
{
// Note that we show -k here because we have an input key name
append_format(stdout_buffer, L"bind -k %ls", tname.c_str());
}
else
{
// No key name, so no -k; we show the escape sequence directly
const wcstring eseq = escape_string(seq, 1);
append_format(stdout_buffer, L"bind %ls", eseq.c_str());
}
// Now show the list of commands
for (size_t i = 0; i < ecmds.size(); i++)
{
wcstring ecmd = ecmds.at(i);
wchar_t *escaped = escape(ecmd.c_str(), 1);
append_format(stdout_buffer, L" %ls", escaped);
free(escaped);
const wcstring &ecmd = ecmds.at(i);
const wcstring escaped_ecmd = escape_string(ecmd, ESCAPE_ALL);
stdout_buffer.push_back(' ');
stdout_buffer.append(escaped_ecmd);
}
append_format(stdout_buffer, L"\n");
stdout_buffer.push_back(L'\n');
}
}

View file

@ -1004,7 +1004,7 @@ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq)
}
bool input_terminfo_get_name(const wcstring &seq, wcstring &name)
bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name)
{
input_init();
@ -1020,7 +1020,7 @@ bool input_terminfo_get_name(const wcstring &seq, wcstring &name)
const wcstring map_buf = format_string(L"%s", m.seq);
if (map_buf == seq)
{
name = m.name;
out_name->assign(m.name);
return true;
}
}

View file

@ -169,8 +169,8 @@ void input_function_set_status(bool status);
*/
bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq);
/** Return the name of the terminfo variable with the specified sequence */
bool input_terminfo_get_name(const wcstring &seq, wcstring &name);
/** 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);
/** Return a list of all known terminfo names */
wcstring_list_t input_terminfo_get_names(bool skip_null);