From b68d3b84de2210862e5900383521a2d4845e4e46 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Mar 2019 17:05:33 -0700 Subject: [PATCH] Switch input_function_get_code() to return maybe_t --- src/builtin_commandline.cpp | 5 ++--- src/input.cpp | 8 ++++---- src/input.h | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index 5f7c27a16..a4fb80f46 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -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); diff --git a/src/input.cpp b/src/input.cpp index 227620dd7..f68c5f179 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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 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(); } diff --git a/src/input.h b/src/input.h index a5d582306..bd3df452b 100644 --- a/src/input.h +++ b/src/input.h @@ -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 input_function_get_code(const wcstring &name); /// Returns a list of all existing input function names. wcstring_list_t input_function_get_names(void);