forked from OctaForge/libcubescript
fixes
parent
d01349886a
commit
ccb35eb1c4
|
@ -5,20 +5,15 @@
|
|||
|
||||
#include <ostd/string.hh>
|
||||
|
||||
static void init_lineedit(cs_state &, ostd::string_range) {
|
||||
inline void init_lineedit(cs_state &, ostd::string_range) {
|
||||
}
|
||||
|
||||
static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
inline std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
ostd::write(pr->get_value());
|
||||
std::string ret;
|
||||
/* i really need to implement some sort of get_line for ostd streams */
|
||||
for (char c = ostd::in.getchar(); c && (c != '\n'); c = ostd::in.getchar()) {
|
||||
ret += c;
|
||||
}
|
||||
return std::move(ret);
|
||||
return std::move(ostd::cin.get_line(ostd::appender<std::string>()).get());
|
||||
}
|
||||
|
||||
static void add_history(cs_state &, ostd::string_range) {
|
||||
inline void add_history(cs_state &, ostd::string_range) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
static cs_state *ln_cs = nullptr;
|
||||
|
||||
static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
||||
inline void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
||||
ostd::string_range cmd = get_complete_cmd(buf);
|
||||
for (auto id: ln_cs->get_idents()) {
|
||||
if (!id->is_command()) {
|
||||
|
@ -32,7 +32,7 @@ static void ln_complete(char const *buf, linenoiseCompletions *lc) {
|
|||
}
|
||||
}
|
||||
|
||||
static char *ln_hint(char const *buf, int *color, int *bold) {
|
||||
inline char *ln_hint(char const *buf, int *color, int *bold) {
|
||||
cs_command *cmd = get_hint_cmd(*ln_cs, buf);
|
||||
if (!cmd) {
|
||||
return nullptr;
|
||||
|
@ -47,11 +47,11 @@ static char *ln_hint(char const *buf, int *color, int *bold) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void ln_hint_free(void *hint) {
|
||||
inline void ln_hint_free(void *hint) {
|
||||
delete[] static_cast<char *>(hint);
|
||||
}
|
||||
|
||||
static void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||
inline void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||
/* sensible default history size */
|
||||
linenoiseHistorySetMaxLen(1000);
|
||||
ln_cs = &cs;
|
||||
|
@ -60,7 +60,7 @@ static void init_lineedit(cs_state &cs, ostd::string_range) {
|
|||
linenoiseSetFreeHintsCallback(ln_hint_free);
|
||||
}
|
||||
|
||||
static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
inline std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
auto line = linenoise(pr->get_value().data());
|
||||
if (!line) {
|
||||
/* linenoise traps ctrl-c, detect it and let the user exit */
|
||||
|
@ -75,7 +75,7 @@ static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
|||
return std::move(ret);
|
||||
}
|
||||
|
||||
static void add_history(cs_state &, ostd::string_range line) {
|
||||
inline void add_history(cs_state &, ostd::string_range line) {
|
||||
/* backed by std::string so it's terminated */
|
||||
linenoiseHistoryAdd(line.data());
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
static cs_state *rd_cs = nullptr;
|
||||
|
||||
static char *ln_complete_list(char const *buf, int state) {
|
||||
inline char *ln_complete_list(char const *buf, int state) {
|
||||
static ostd::string_range cmd;
|
||||
static ostd::PointerRange<cs_ident *> itr;
|
||||
static ostd::iterator_range<cs_ident **> itr;
|
||||
|
||||
if (!state) {
|
||||
cmd = get_complete_cmd(buf);
|
||||
|
@ -41,12 +41,12 @@ static char *ln_complete_list(char const *buf, int state) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static char **ln_complete(char const *buf, int, int) {
|
||||
inline char **ln_complete(char const *buf, int, int) {
|
||||
rl_attempted_completion_over = 1;
|
||||
return rl_completion_matches(buf, ln_complete_list);
|
||||
}
|
||||
|
||||
void ln_hint() {
|
||||
inline void ln_hint() {
|
||||
cs_command *cmd = get_hint_cmd(*rd_cs, rl_line_buffer);
|
||||
if (!cmd) {
|
||||
rl_redisplay();
|
||||
|
@ -63,13 +63,13 @@ void ln_hint() {
|
|||
rl_replace_line(old.data(), 0);
|
||||
}
|
||||
|
||||
static void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||
inline void init_lineedit(cs_state &cs, ostd::string_range) {
|
||||
rd_cs = &cs;
|
||||
rl_attempted_completion_function = ln_complete;
|
||||
rl_redisplay_function = ln_hint;
|
||||
}
|
||||
|
||||
static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
inline std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
||||
auto line = readline(pr->get_value().data());
|
||||
if (!line) {
|
||||
return std::string();
|
||||
|
@ -79,7 +79,7 @@ static std::optional<std::string> read_line(cs_state &, cs_svar *pr) {
|
|||
return std::move(ret);
|
||||
}
|
||||
|
||||
static void add_history(cs_state &, ostd::string_range line) {
|
||||
inline void add_history(cs_state &, ostd::string_range line) {
|
||||
/* backed by std::string so it's terminated */
|
||||
add_history(line.data());
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ static bool stdin_is_tty() {
|
|||
|
||||
/* line editing support */
|
||||
|
||||
static inline ostd::string_range get_complete_cmd(ostd::string_range buf) {
|
||||
inline ostd::string_range get_complete_cmd(ostd::string_range buf) {
|
||||
ostd::string_range not_allowed = "\"/;()[] \t\r\n\0";
|
||||
ostd::string_range found = ostd::find_one_of(buf, not_allowed);
|
||||
while (!found.empty()) {
|
||||
|
@ -39,7 +39,7 @@ static inline ostd::string_range get_complete_cmd(ostd::string_range buf) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
static inline ostd::string_range get_arg_type(char arg) {
|
||||
inline ostd::string_range get_arg_type(char arg) {
|
||||
switch (arg) {
|
||||
case 'i':
|
||||
return "int";
|
||||
|
@ -71,7 +71,7 @@ static inline ostd::string_range get_arg_type(char arg) {
|
|||
return "illegal";
|
||||
}
|
||||
|
||||
static inline void fill_cmd_args(std::string &writer, ostd::string_range args) {
|
||||
inline void fill_cmd_args(std::string &writer, ostd::string_range args) {
|
||||
char variadic = '\0';
|
||||
int nrep = 0;
|
||||
if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) {
|
||||
|
@ -128,7 +128,7 @@ static inline void fill_cmd_args(std::string &writer, ostd::string_range args) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) {
|
||||
inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) {
|
||||
ostd::string_range nextchars = "([;";
|
||||
auto lp = ostd::find_one_of(buf, nextchars);
|
||||
if (!lp.empty()) {
|
||||
|
|
Loading…
Reference in New Issue