switch to modified cpp-linenoise, use it on windows
parent
b9c74d86b5
commit
6068a7259b
|
@ -1,5 +1,4 @@
|
||||||
#ifdef CS_REPL_USE_LINENOISE
|
#ifdef CS_REPL_USE_LINENOISE
|
||||||
#ifndef _WIN32
|
|
||||||
#ifndef CS_REPL_HAS_EDIT
|
#ifndef CS_REPL_HAS_EDIT
|
||||||
#define CS_REPL_HAS_EDIT
|
#define CS_REPL_HAS_EDIT
|
||||||
/* use the bundled linenoise library, default */
|
/* use the bundled linenoise library, default */
|
||||||
|
@ -14,7 +13,7 @@
|
||||||
|
|
||||||
static cs::state *ln_cs = nullptr;
|
static cs::state *ln_cs = nullptr;
|
||||||
|
|
||||||
inline void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
inline void ln_complete(char const *buf, std::vector<std::string> &lc) {
|
||||||
std::string_view cmd = get_complete_cmd(buf);
|
std::string_view cmd = get_complete_cmd(buf);
|
||||||
for (auto id: ln_cs->get_idents()) {
|
for (auto id: ln_cs->get_idents()) {
|
||||||
if (!id->is_command()) {
|
if (!id->is_command()) {
|
||||||
|
@ -25,24 +24,22 @@ inline void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (idname.substr(0, cmd.size()) == cmd) {
|
if (idname.substr(0, cmd.size()) == cmd) {
|
||||||
linenoiseAddCompletion(lc, idname.data());
|
lc.emplace_back(idname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char *ln_hint(char const *buf, int *color, int *bold) {
|
inline std::string ln_hint(char const *buf, int &color, int &bold) {
|
||||||
cs::command *cmd = get_hint_cmd(*ln_cs, buf);
|
cs::command *cmd = get_hint_cmd(*ln_cs, buf);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
return nullptr;
|
return std::string{};
|
||||||
}
|
}
|
||||||
std::string args = " [";
|
std::string args = " [";
|
||||||
fill_cmd_args(args, cmd->get_args());
|
fill_cmd_args(args, cmd->get_args());
|
||||||
args += ']';
|
args += ']';
|
||||||
*color = 35;
|
color = 35;
|
||||||
*bold = 1;
|
bold = 1;
|
||||||
char *ret = new char[args.size() + 1];
|
return args;
|
||||||
memcpy(ret, args.data(), args.size() + 1);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ln_hint_free(void *hint) {
|
inline void ln_hint_free(void *hint) {
|
||||||
|
@ -51,16 +48,16 @@ inline void ln_hint_free(void *hint) {
|
||||||
|
|
||||||
inline void init_lineedit(cs::state &cs, std::string_view) {
|
inline void init_lineedit(cs::state &cs, std::string_view) {
|
||||||
/* sensible default history size */
|
/* sensible default history size */
|
||||||
linenoiseHistorySetMaxLen(1000);
|
linenoise::SetHistoryMaxLen(1000);
|
||||||
ln_cs = &cs;
|
ln_cs = &cs;
|
||||||
linenoiseSetCompletionCallback(ln_complete);
|
linenoise::SetCompletionCallback(ln_complete);
|
||||||
linenoiseSetHintsCallback(ln_hint);
|
linenoise::SetHintsCallback(ln_hint);
|
||||||
linenoiseSetFreeHintsCallback(ln_hint_free);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::optional<std::string> read_line(cs::state &, cs::string_var *pr) {
|
inline std::optional<std::string> read_line(cs::state &, cs::string_var *pr) {
|
||||||
auto line = linenoise(pr->get_value().data());
|
std::string line;
|
||||||
if (!line) {
|
auto quit = linenoise::Readline(pr->get_value().data(), line);
|
||||||
|
if (quit) {
|
||||||
/* linenoise traps ctrl-c, detect it and let the user exit */
|
/* linenoise traps ctrl-c, detect it and let the user exit */
|
||||||
if (errno == EAGAIN) {
|
if (errno == EAGAIN) {
|
||||||
raise(SIGINT);
|
raise(SIGINT);
|
||||||
|
@ -68,16 +65,13 @@ inline std::optional<std::string> read_line(cs::state &, cs::string_var *pr) {
|
||||||
}
|
}
|
||||||
return std::string{};
|
return std::string{};
|
||||||
}
|
}
|
||||||
std::string ret = line;
|
return line;
|
||||||
linenoiseFree(line);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void add_history(cs::state &, std::string_view line) {
|
inline void add_history(cs::state &, std::string_view line) {
|
||||||
/* backed by std::string so it's terminated */
|
/* backed by std::string so it's terminated */
|
||||||
linenoiseHistoryAdd(line.data());
|
linenoise::AddHistory(line.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
1225
tools/linenoise.cc
1225
tools/linenoise.cc
File diff suppressed because it is too large
Load Diff
2461
tools/linenoise.hh
2461
tools/linenoise.hh
File diff suppressed because it is too large
Load Diff
|
@ -8,12 +8,9 @@ repl_flags = []
|
||||||
if get_option('readline').enabled()
|
if get_option('readline').enabled()
|
||||||
use_readline = true
|
use_readline = true
|
||||||
use_linenoise = false
|
use_linenoise = false
|
||||||
elif get_option('linenoise').enabled()
|
elif not get_option('linenoise').disabled()
|
||||||
use_readline = false
|
use_readline = false
|
||||||
use_linenoise = true
|
use_linenoise = true
|
||||||
elif get_option('linenoise').auto()
|
|
||||||
use_readline = false
|
|
||||||
use_linenoise = (host_machine.system() != 'windows')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if not get_option('repl').disabled()
|
if not get_option('repl').disabled()
|
||||||
|
@ -21,7 +18,6 @@ if not get_option('repl').disabled()
|
||||||
repl_deps += [dependency('readline')]
|
repl_deps += [dependency('readline')]
|
||||||
repl_flags = ['-DCS_REPL_USE_READLINE']
|
repl_flags = ['-DCS_REPL_USE_READLINE']
|
||||||
elif use_linenoise
|
elif use_linenoise
|
||||||
repl_src += ['linenoise.cc']
|
|
||||||
repl_flags = ['-DCS_REPL_USE_LINENOISE']
|
repl_flags = ['-DCS_REPL_USE_LINENOISE']
|
||||||
endif
|
endif
|
||||||
executable('cubescript',
|
executable('cubescript',
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
/* avoid silly complaints about fopen */
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define _CRT_SECURE_NO_WARNINGS 1
|
/* avoid silly complaints about fopen */
|
||||||
|
# define _CRT_SECURE_NO_WARNINGS 1
|
||||||
|
/* work around clang bug with std::function (needed by linenoise) */
|
||||||
|
# if defined(__clang__) && !defined(_HAS_STATIC_RTTI)
|
||||||
|
# define _HAS_STATIC_RTTI 0
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
Loading…
Reference in New Issue