drop readline support in repl
this library is bad, and its documentation is even worse and our linenoise now supports every non-boomer platform already anywaymaster
parent
ad1c345401
commit
36bf0e368f
|
@ -4,12 +4,6 @@ option('repl',
|
|||
description: 'Enable the REPL (command line tool)'
|
||||
)
|
||||
|
||||
option('readline',
|
||||
type: 'feature',
|
||||
value: 'auto',
|
||||
description: 'Use GNU readline for the REPL'
|
||||
)
|
||||
|
||||
option('linenoise',
|
||||
type: 'feature',
|
||||
value: 'auto',
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
#ifdef CS_REPL_USE_READLINE
|
||||
#ifndef CS_REPL_HAS_EDIT
|
||||
#define CS_REPL_HAS_EDIT
|
||||
/* use the GNU readline library */
|
||||
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
static cs::state *rd_cs = nullptr;
|
||||
|
||||
inline char *ln_complete_list(char const *buf, int state) {
|
||||
static std::string_view cmd;
|
||||
static std::span<cs::ident *> itr;
|
||||
|
||||
if (!state) {
|
||||
cmd = get_complete_cmd(buf);
|
||||
itr = rd_cs->get_idents();
|
||||
}
|
||||
|
||||
for (cs::ident *id: itr) {
|
||||
if (!id->is_command()) {
|
||||
continue;
|
||||
}
|
||||
std::string_view idname = id->get_name();
|
||||
if (idname.size() <= cmd.size()) {
|
||||
continue;
|
||||
}
|
||||
if (idname.substr(0, cmd.size()) == cmd) {
|
||||
++itr;
|
||||
return strdup(idname.data());
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline char **ln_complete(char const *buf, int, int) {
|
||||
rl_attempted_completion_over = 1;
|
||||
return rl_completion_matches(buf, ln_complete_list);
|
||||
}
|
||||
|
||||
inline void ln_hint() {
|
||||
cs::command *cmd = get_hint_cmd(*rd_cs, rl_line_buffer);
|
||||
if (!cmd) {
|
||||
rl_redisplay();
|
||||
return;
|
||||
}
|
||||
std::string old = rl_line_buffer;
|
||||
std::string args = old;
|
||||
args += " [";
|
||||
fill_cmd_args(args, cmd->get_args());
|
||||
args += "] ";
|
||||
rl_extend_line_buffer(args.size());
|
||||
rl_replace_line(args.data(), 0);
|
||||
rl_redisplay();
|
||||
rl_replace_line(old.data(), 0);
|
||||
}
|
||||
|
||||
inline void init_lineedit(cs::state &cs, std::string_view) {
|
||||
rd_cs = &cs;
|
||||
rl_attempted_completion_function = ln_complete;
|
||||
rl_redisplay_function = ln_hint;
|
||||
}
|
||||
|
||||
inline std::optional<std::string> read_line(cs::state &, cs::string_var &pr) {
|
||||
auto line = readline(pr.get_value().data());
|
||||
if (!line) {
|
||||
return std::string();
|
||||
}
|
||||
std::string ret = line;
|
||||
free(line);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void add_history(cs::state &, std::string_view line) {
|
||||
/* backed by std::string so it's terminated */
|
||||
add_history(line.data());
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -5,19 +5,8 @@ repl_src = [
|
|||
repl_deps = [libcubescript]
|
||||
repl_flags = []
|
||||
|
||||
if get_option('readline').enabled()
|
||||
use_readline = true
|
||||
use_linenoise = false
|
||||
elif not get_option('linenoise').disabled()
|
||||
use_readline = false
|
||||
use_linenoise = true
|
||||
endif
|
||||
|
||||
if not get_option('repl').disabled()
|
||||
if use_readline
|
||||
repl_deps += [dependency('readline')]
|
||||
repl_flags = ['-DCS_REPL_USE_READLINE']
|
||||
elif use_linenoise
|
||||
if not get_option('linenoise').disabled()
|
||||
repl_flags = ['-DCS_REPL_USE_LINENOISE']
|
||||
endif
|
||||
executable('cubescript',
|
||||
|
|
|
@ -165,7 +165,6 @@ inline cs::command *get_hint_cmd(cs::state &cs, std::string_view buf) {
|
|||
}
|
||||
|
||||
#include "edit_linenoise.hh"
|
||||
#include "edit_readline.hh"
|
||||
#include "edit_fallback.hh"
|
||||
|
||||
/* usage */
|
||||
|
|
Loading…
Reference in New Issue