diff options
Diffstat (limited to 'linenoise/linenoise.c')
-rw-r--r-- | linenoise/linenoise.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 7c945964..9e2b159f 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -98,8 +98,10 @@ struct lino_state { lino_compl_cb_t *completion_callback; #endif void *cb_ctx; /* User context for completion callback */ +#if HAVE_TERMIOS lino_atom_cb_t *atom_callback; void *ca_ctx; /* User context for atom callback */ +#endif lino_enter_cb_t *enter_callback; void *ce_ctx; /* User context for enter callback */ #if HAVE_TERMIOS @@ -108,23 +110,30 @@ struct lino_state { #ifdef __CYGWIN__ int orig_imode, orig_omode; #endif +#if HAVE_TERMIOS int rawmode; /* For atexit() function to check if restore is needed*/ int mlmode; /* Multi line mode. Default is single line. */ +#endif int history_max_len; int history_len; int loaded_lines; /* How many lines come from load. */ wchar_t **history; +#if HAVE_TERMIOS wchar_t *clip; /* Selection */ wchar_t *result; /* Previous command result. */ +#endif mem_t *tty_ifs; /* Terminal input file stream. */ mem_t *tty_ofs; /* Terminal output file stream. */ int save_hist_idx; /* Jump to history position on entry into edit */ /* Volatile state pertaining to just one linenoise call */ +#if HAVE_TERMIOS wchar_t buf[LINENOISE_MAX_DISP]; /* Displayed line buffer. */ +#endif wchar_t data[LINENOISE_MAX_LINE]; /* True data corresponding to display */ const wchar_t *prompt; /* Prompt to display. */ const char *suffix; /* Suffix when creating temp file. */ +#if HAVE_TERMIOS int plen; /* Prompt length. */ int pos; /* Current cursor position. */ int sel; /* Selection start in terms of display. */ @@ -143,8 +152,11 @@ struct lino_state { int selmode; /* Visual selection being made. */ int selinclusive; /* Selections include character right of endpoint. */ int noninteractive; /* No character editing, even if input is tty. */ +#endif int show_prompt; /* Show prompting in non-interactive mode. */ +#if HAVE_TERMIOS struct lino_undo *undo_stack; +#endif lino_error_t error; /* Most recent error. */ }; @@ -192,6 +204,7 @@ static int wcsnprintf(wchar_t *s, size_t nchar, const wchar_t *fmt, ...) /* ======================= Low level terminal handling ====================== */ +#if HAVE_TERMIOS /* Set if to use or not the multi line mode. */ void lino_set_multiline(lino_t *ls, int ml) { ls->mlmode = ml; @@ -210,6 +223,7 @@ int lino_get_selinculsive(lino_t *ls) return ls->selinclusive; } + void lino_set_noninteractive(lino_t *ls, int ni) { ls->noninteractive = ni; @@ -220,17 +234,23 @@ int lino_get_noninteractive(lino_t *ls) return ls->noninteractive; } +#endif + void lino_enable_noninteractive_prompt(lino_t *ls, int enable) { ls->show_prompt = enable; } +#if HAVE_TERMIOS + void lino_set_atom_cb(lino_t *l, lino_atom_cb_t *cb, void *ctx) { l->atom_callback = cb; l->ca_ctx = ctx; } +#endif + void lino_set_enter_cb(lino_t *l, lino_enter_cb_t *cb, void *ctx) { l->enter_callback = cb; @@ -2548,11 +2568,19 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) { int ifd = lino_os.fileno_fn(ls->tty_ifs); - if (ls->noninteractive || !isatty(ifd)) { +#if HAVE_TERMIOS + int noninteractive = ls->noninteractive; + int plain = noninteractive || !isatty(ifd); +#else + int noninteractive = 1; + int plain = 1; +#endif + + if (plain) { wchar_t *ret = 0; size_t len = 0, i; const wchar_t *condensed_prompt = prompt + wcslen(prompt); - int show_prompt = ls->show_prompt || (ls->noninteractive && isatty(ifd)); + int show_prompt = ls->show_prompt || (noninteractive && isatty(ifd)); if (show_prompt) { while (condensed_prompt > prompt && @@ -2666,9 +2694,6 @@ lino_t *lino_make(mem_t *ifs, mem_t *ofs) ls->tty_ofs = ofs; link_into_list(&lino_list, ls); -#if !HAVE_TERMIOS - ls->noninteractive = 1; -#endif } return ls; @@ -2682,10 +2707,12 @@ lino_t *lino_copy(lino_t *le) *ls = *le; ls->history_len = 0; ls->history = 0; +#if HAVE_TERMIOS ls->rawmode = 0; ls->clip = 0; ls->result = 0; ls->undo_stack = 0; +#endif link_into_list(&lino_list, ls); } @@ -2704,11 +2731,11 @@ static void lino_cleanup(lino_t *ls) free_hist(ls); #if HAVE_TERMIOS free_undo_stack(ls); -#endif lino_os.free_fn(ls->clip); ls->clip = 0; lino_os.free_fn(ls->result); ls->result = 0; +#endif } void lino_free(lino_t *ls) @@ -2908,6 +2935,8 @@ int lino_have_new_lines(lino_t *ls) return ls->history_len > ls->loaded_lines; } +#if HAVE_TERMIOS + void lino_set_result(lino_t *ls, wchar_t *res) { lino_os.free_fn(ls->result); @@ -2916,6 +2945,8 @@ void lino_set_result(lino_t *ls, wchar_t *res) *res = '\r'; } +#endif + void lino_init(lino_os_t *os) { lino_os = *os; |