summaryrefslogtreecommitdiffstats
path: root/src/readline_context.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/readline_context.hh')
-rw-r--r--src/readline_context.hh53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/readline_context.hh b/src/readline_context.hh
index 047cf56..99f1742 100644
--- a/src/readline_context.hh
+++ b/src/readline_context.hh
@@ -44,7 +44,7 @@
class attr_line_t;
struct exec_context;
-typedef void (*readline_highlighter_t)(attr_line_t& line, int x);
+using readline_highlighter_t = void (*)(attr_line_t& line, int x);
/**
* Container for information related to different readline contexts. Since
@@ -53,30 +53,50 @@ typedef void (*readline_highlighter_t)(attr_line_t& line, int x);
*/
class readline_context {
public:
- typedef Result<std::string, lnav::console::user_message> (*command_func_t)(
+ using command_func_t = Result<std::string, lnav::console::user_message> (*)(
exec_context& ec, std::string cmdline, std::vector<std::string>& args);
- typedef std::string (*prompt_func_t)(exec_context& ec,
- const std::string& cmdline);
- typedef struct _command_t {
+
+ struct prompt_result_t {
+ std::string pr_new_prompt;
+ std::string pr_suggestion;
+ };
+
+ struct stage {
+ std::vector<line_range> s_args;
+ };
+
+ struct split_result_t {
+ std::vector<stage> sr_stages;
+ };
+
+ using prompt_func_t
+ = prompt_result_t (*)(exec_context& ec, const std::string& cmdline);
+ using splitter_func_t
+ = split_result_t (*)(readline_context& rc, const std::string& cmdline);
+ using command_t = struct _command_t {
const char* c_name;
command_func_t c_func;
struct help_text c_help;
prompt_func_t c_prompt{nullptr};
+ std::string c_provides;
+ std::set<std::string> c_dependencies;
_command_t(const char* name,
command_func_t func,
help_text help = {},
- prompt_func_t prompt = nullptr) noexcept
+ prompt_func_t prompt = nullptr,
+ std::string provides = {},
+ std::set<std::string> deps = {}) noexcept
: c_name(name), c_func(func), c_help(std::move(help)),
- c_prompt(prompt)
+ c_prompt(prompt), c_provides(provides), c_dependencies(deps)
{
}
_command_t(command_func_t func) noexcept : c_name("anon"), c_func(func)
{
}
- } command_t;
+ };
typedef std::map<std::string, command_t*> command_map_t;
readline_context(std::string name,
@@ -87,6 +107,8 @@ public:
void load();
+ void set_history();
+
void save();
void add_possibility(const std::string& type, const std::string& value)
@@ -113,10 +135,7 @@ public:
return *this;
}
- int get_append_character() const
- {
- return this->rc_append_character;
- }
+ int get_append_character() const { return this->rc_append_character; }
readline_context& set_highlighter(readline_highlighter_t hl)
{
@@ -143,6 +162,12 @@ public:
return this->rc_highlighter;
}
+ readline_context& with_splitter(splitter_func_t sf)
+ {
+ this->rc_splitter = sf;
+ return *this;
+ }
+
static int command_complete(int, int);
std::map<std::string, std::string> rc_prefixes;
@@ -173,11 +198,13 @@ private:
HISTORY_STATE rc_history;
std::map<std::string, std::set<std::string>> rc_possibilities;
std::map<std::string, std::vector<std::string>> rc_prototypes;
+ std::map<std::string, command_t*> rc_commands;
bool rc_case_sensitive;
- int rc_append_character;
+ int rc_append_character{' '};
const char* rc_quote_chars;
readline_highlighter_t rc_highlighter;
std::vector<readline_var> rc_vars;
+ splitter_func_t rc_splitter{nullptr};
};
#endif