forked from OctaForge/libcubescript
repl cleanup
parent
7f1c6b03a8
commit
da8120f5c8
3
Makefile
3
Makefile
|
@ -30,8 +30,7 @@ $(LIBCS_LIB): $(LIBCS_OBJ)
|
|||
|
||||
repl: $(LIBCS_LIB) tools/repl.cc tools/linenoise.cc tools/linenoise.hh
|
||||
$(CXX) $(CXXFLAGS) $(LIBCS_CXXFLAGS) $(LDFLAGS) \
|
||||
-DCS_REPL_USE_LINENOISE -DCS_REPL_HAS_HINTS -DCS_REPL_HAS_COMPLETE \
|
||||
tools/linenoise.cc tools/repl.cc -o repl $(LIBCS_LIB)
|
||||
-DCS_REPL_USE_LINENOISE tools/linenoise.cc tools/repl.cc -o repl $(LIBCS_LIB)
|
||||
|
||||
clean:
|
||||
rm -f $(LIBCS_LIB) $(LIBCS_OBJ) repl
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
static CsState *ln_cs = nullptr;
|
||||
|
||||
#ifdef CS_REPL_HAS_COMPLETE
|
||||
static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
||||
ostd::ConstCharRange cmd = get_complete_cmd(buf);
|
||||
for (auto id: ln_cs->get_idents()) {
|
||||
|
@ -31,9 +30,7 @@ static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif /* CS_REPL_HAS_COMPLETE */
|
||||
|
||||
#ifdef CS_REPL_HAS_HINTS
|
||||
static char *ln_hint(char const *buf, int *color, int *bold) {
|
||||
CsCommand *cmd = get_hint_cmd(*ln_cs, buf);
|
||||
if (!cmd) {
|
||||
|
@ -52,19 +49,14 @@ static char *ln_hint(char const *buf, int *color, int *bold) {
|
|||
static void ln_hint_free(void *hint) {
|
||||
delete[] static_cast<char *>(hint);
|
||||
}
|
||||
#endif /* CS_REPL_HAS_HINTS */
|
||||
|
||||
static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
|
||||
/* sensible default history size */
|
||||
linenoiseHistorySetMaxLen(1000);
|
||||
ln_cs = &cs;
|
||||
#ifdef CS_REPL_HAS_COMPLETE
|
||||
linenoiseSetCompletionCallback(ln_complete);
|
||||
#endif
|
||||
#ifdef CS_REPL_HAS_HINTS
|
||||
linenoiseSetHintsCallback(ln_hint);
|
||||
linenoiseSetFreeHintsCallback(ln_hint_free);
|
||||
#endif
|
||||
}
|
||||
|
||||
static ostd::Maybe<ostd::String> read_line(CsState &, CsSvar *pr) {
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
static CsState *rd_cs = nullptr;
|
||||
|
||||
#ifdef CS_REPL_HAS_COMPLETE
|
||||
static char *ln_complete_list(char const *buf, int state) {
|
||||
static ostd::ConstCharRange cmd;
|
||||
static ostd::PointerRange<CsIdent *> itr;
|
||||
|
@ -45,9 +44,7 @@ static char **ln_complete(char const *buf, int, int) {
|
|||
rl_attempted_completion_over = 1;
|
||||
return rl_completion_matches(buf, ln_complete_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CS_REPL_HAS_HINTS
|
||||
void ln_hint() {
|
||||
CsCommand *cmd = get_hint_cmd(*rd_cs, rl_line_buffer);
|
||||
if (!cmd) {
|
||||
|
@ -64,16 +61,11 @@ void ln_hint() {
|
|||
rl_redisplay();
|
||||
rl_replace_line(old.data(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_lineedit(CsState &cs, ostd::ConstCharRange) {
|
||||
rd_cs = &cs;
|
||||
#ifdef CS_REPL_HAS_COMPLETE
|
||||
rl_attempted_completion_function = ln_complete;
|
||||
#endif
|
||||
#ifdef CS_REPL_HAS_HINTS
|
||||
rl_redisplay_function = ln_hint;
|
||||
#endif
|
||||
}
|
||||
|
||||
static ostd::Maybe<ostd::String> read_line(CsState &, CsSvar *pr) {
|
||||
|
|
|
@ -27,8 +27,7 @@ static bool stdin_is_tty() {
|
|||
|
||||
/* line editing support */
|
||||
|
||||
#ifdef CS_REPL_HAS_COMPLETE
|
||||
static ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) {
|
||||
static inline ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) {
|
||||
ostd::ConstCharRange not_allowed = "\"/;()[] \t\r\n\0";
|
||||
ostd::ConstCharRange found = ostd::find_one_of(buf, not_allowed);
|
||||
while (!found.empty()) {
|
||||
|
@ -38,9 +37,7 @@ static ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) {
|
|||
}
|
||||
return buf;
|
||||
}
|
||||
#endif /* CS_REPL_HAS_COMPLETE */
|
||||
|
||||
#ifdef CS_REPL_HAS_HINTS
|
||||
static inline ostd::ConstCharRange get_arg_type(char arg) {
|
||||
switch (arg) {
|
||||
case 'i':
|
||||
|
@ -73,7 +70,7 @@ static inline ostd::ConstCharRange get_arg_type(char arg) {
|
|||
return "illegal";
|
||||
}
|
||||
|
||||
static void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) {
|
||||
static inline void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) {
|
||||
char variadic = '\0';
|
||||
int nrep = 0;
|
||||
if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) {
|
||||
|
@ -130,7 +127,7 @@ static void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) {
|
|||
}
|
||||
}
|
||||
|
||||
static CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) {
|
||||
static inline CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) {
|
||||
ostd::ConstCharRange nextchars = "([;";
|
||||
auto lp = ostd::find_one_of(buf, nextchars);
|
||||
if (!lp.empty()) {
|
||||
|
@ -153,7 +150,6 @@ static CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) {
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif /* CS_REPL_HAS_HINTS */
|
||||
|
||||
#include "edit_linenoise.hh"
|
||||
#include "edit_readline.hh"
|
||||
|
|
Loading…
Reference in New Issue