Switch input_function_get_code() to return maybe_t

This commit is contained in:
ridiculousfish 2019-03-16 17:05:33 -07:00
parent c2be5e8986
commit b68d3b84de
3 changed files with 7 additions and 9 deletions

View file

@ -325,11 +325,10 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
}
for (i = w.woptind; i < argc; i++) {
wchar_t c = input_function_get_code(argv[i]);
if (c != INPUT_CODE_NONE) {
if (auto mc = input_function_get_code(argv[i])) {
// input_unreadch inserts the specified keypress or readline function at the back of
// the queue of unused keypresses.
input_queue_ch(c);
input_queue_ch(*mc);
} else {
streams.err.append_format(_(L"%ls: Unknown input function '%ls'"), cmd, argv[i]);
builtin_print_help(parser, streams, cmd, streams.err);

View file

@ -335,7 +335,7 @@ static void input_mapping_execute(const input_mapping_t &m, bool allow_commands)
bool has_commands = false, has_functions = false;
for (const wcstring &cmd : m.commands) {
if (input_function_get_code(cmd) != INPUT_CODE_NONE)
if (input_function_get_code(cmd))
has_functions = true;
else
has_commands = true;
@ -360,7 +360,7 @@ static void input_mapping_execute(const input_mapping_t &m, bool allow_commands)
for (wcstring_list_t::const_reverse_iterator it = m.commands.rbegin(),
end = m.commands.rend();
it != end; ++it) {
wchar_t code = input_function_get_code(*it);
wchar_t code = input_function_get_code(*it).value();
input_function_push_args(code);
input_common_next_ch(code);
}
@ -794,11 +794,11 @@ wcstring_list_t input_function_get_names() {
return result;
}
wchar_t input_function_get_code(const wcstring &name) {
maybe_t<wchar_t> input_function_get_code(const wcstring &name) {
for (const auto &md : input_function_metadata) {
if (name == md.name) {
return md.code;
}
}
return INPUT_CODE_NONE;
return none();
}

View file

@ -95,8 +95,7 @@ bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name);
wcstring_list_t input_terminfo_get_names(bool skip_null);
/// Returns the input function code for the given input function name.
#define INPUT_CODE_NONE (wchar_t(-1))
wchar_t input_function_get_code(const wcstring &name);
maybe_t<wchar_t> input_function_get_code(const wcstring &name);
/// Returns a list of all existing input function names.
wcstring_list_t input_function_get_names(void);