diff --git a/src/builtin_bind.cpp b/src/builtin_bind.cpp index 502464037..7a390e9fb 100644 --- a/src/builtin_bind.cpp +++ b/src/builtin_bind.cpp @@ -35,6 +35,36 @@ struct bind_cmd_opts_t { const wchar_t *sets_bind_mode = L""; }; +namespace { +class builtin_bind_t { + public: + maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv); + + builtin_bind_t() : input_mappings_(input_mappings()) {} + + private: + bind_cmd_opts_t *opts; + + /// Note that builtin_bind_t holds the singleton lock. + /// It must not call out to anything which can execute fish shell code or attempt to acquire the + /// lock again. + acquired_lock input_mappings_; + + void list(const wchar_t *bind_mode, bool user, io_streams_t &streams); + void key_names(bool all, io_streams_t &streams); + void function_names(io_streams_t &streams); + bool add(const wcstring &seq, const wchar_t *const *cmds, size_t cmds_len, const wchar_t *mode, + const wchar_t *sets_mode, bool terminfo, bool user, io_streams_t &streams); + bool erase(const wchar_t *const *seq, bool all, const wchar_t *mode, bool use_terminfo, + bool user, io_streams_t &streams); + bool get_terminfo_sequence(const wcstring &seq, wcstring *out_seq, io_streams_t &streams) const; + bool insert(int optind, int argc, const wchar_t **argv, io_streams_t &streams); + void list_modes(io_streams_t &streams); + bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams); + bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, + io_streams_t &streams); +}; + /// List a single key binding. /// Returns false if no binding with that sequence and mode exists. bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bool user, @@ -398,6 +428,8 @@ static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high nc return STATUS_CMD_OK; } +} // namespace + /// The bind builtin, used for setting character sequences. maybe_t builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { @@ -461,3 +493,8 @@ maybe_t builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &stream return STATUS_CMD_OK; } + +maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { + builtin_bind_t bind; + return bind.builtin_bind(parser, streams, argv); +} diff --git a/src/builtin_bind.h b/src/builtin_bind.h index 26951564d..8539aff9b 100644 --- a/src/builtin_bind.h +++ b/src/builtin_bind.h @@ -2,45 +2,12 @@ #ifndef FISH_BUILTIN_BIND_H #define FISH_BUILTIN_BIND_H -#include "common.h" -#include "input.h" +#include + +#include "maybe.h" class parser_t; struct io_streams_t; -struct bind_cmd_opts_t; - -class builtin_bind_t { - public: - maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv); - - builtin_bind_t() : input_mappings_(input_mappings()) {} - - private: - bind_cmd_opts_t *opts; - - /// Note that builtin_bind_t holds the singleton lock. - /// It must not call out to anything which can execute fish shell code or attempt to acquire the - /// lock again. - acquired_lock input_mappings_; - - void list(const wchar_t *bind_mode, bool user, io_streams_t &streams); - void key_names(bool all, io_streams_t &streams); - void function_names(io_streams_t &streams); - bool add(const wcstring &seq, const wchar_t *const *cmds, size_t cmds_len, const wchar_t *mode, - const wchar_t *sets_mode, bool terminfo, bool user, io_streams_t &streams); - bool erase(const wchar_t *const *seq, bool all, const wchar_t *mode, bool use_terminfo, - bool user, io_streams_t &streams); - bool get_terminfo_sequence(const wcstring &seq, wcstring *out_seq, io_streams_t &streams) const; - bool insert(int optind, int argc, const wchar_t **argv, io_streams_t &streams); - void list_modes(io_streams_t &streams); - bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, io_streams_t &streams); - bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, - io_streams_t &streams); -}; - -inline maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { - builtin_bind_t bind; - return bind.builtin_bind(parser, streams, argv); -} +maybe_t builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif diff --git a/src/builtin_set.h b/src/builtin_set.h index e7ea6ddd8..205395d70 100644 --- a/src/builtin_set.h +++ b/src/builtin_set.h @@ -2,10 +2,11 @@ #ifndef FISH_BUILTIN_SET_H #define FISH_BUILTIN_SET_H -#include #include -class parser_t; +#include "maybe.h" +class parser_t; +struct io_streams_t; maybe_t builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv); #endif