Move builtin_bind to out-of-line

There was no point in inlining this code.
This commit is contained in:
ridiculousfish 2021-05-25 17:39:55 -07:00
parent 73998b81b4
commit 9820307d23
3 changed files with 44 additions and 39 deletions

View file

@ -35,6 +35,36 @@ struct bind_cmd_opts_t {
const wchar_t *sets_bind_mode = L"";
};
namespace {
class builtin_bind_t {
public:
maybe_t<int> 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_mapping_set_t> 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<int> builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &streams,
const wchar_t **argv) {
@ -461,3 +493,8 @@ maybe_t<int> builtin_bind_t::builtin_bind(parser_t &parser, io_streams_t &stream
return STATUS_CMD_OK;
}
maybe_t<int> builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
builtin_bind_t bind;
return bind.builtin_bind(parser, streams, argv);
}

View file

@ -2,45 +2,12 @@
#ifndef FISH_BUILTIN_BIND_H
#define FISH_BUILTIN_BIND_H
#include "common.h"
#include "input.h"
#include <cwchar>
#include "maybe.h"
class parser_t;
struct io_streams_t;
struct bind_cmd_opts_t;
class builtin_bind_t {
public:
maybe_t<int> 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_mapping_set_t> 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<int> 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<int> builtin_bind(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif

View file

@ -2,10 +2,11 @@
#ifndef FISH_BUILTIN_SET_H
#define FISH_BUILTIN_SET_H
#include <cstring>
#include <cwchar>
class parser_t;
#include "maybe.h"
class parser_t;
struct io_streams_t;
maybe_t<int> builtin_set(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
#endif