diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-08-20 06:31:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-08-20 06:31:14 -0700 |
commit | cabd313483e2f2d23aebb9710458b67f0933f98b (patch) | |
tree | f3fe46b63cd0883fe9d269958618dfff3ee9f7a8 /linenoise | |
parent | 4aaf96f5aaab5c249c3c8ea6d24ee6683bca6f10 (diff) | |
download | txr-cabd313483e2f2d23aebb9710458b67f0933f98b.tar.gz txr-cabd313483e2f2d23aebb9710458b67f0933f98b.tar.bz2 txr-cabd313483e2f2d23aebb9710458b67f0933f98b.zip |
listener: additional reductions in non-termios build.
* linenoise/linenoise.c (struct lino_state): these members are
now absent in non-termios build: atom_callback, ca_ctx,
rawmode, mlmode, clip, result, buf, plen, pos, sel, end, len,
dlen, dpos, dsel, dend, cols, oldrow, maxrows, history_index,
need_resize, need_refresh, selmode, selinclusive,
noninteractive and undo_stack.
(lino_set_multiline, lino_get_multiline,
lino_set_selinclusive, lino_get_selinculsive,
lino_set_noninteractive, lino_get_noninteractive,
lino_set_atom_cb): Functions now only defined in termios
build.
(linenoise): Adjustments for missing members in non-termios
mode.
(lino_make): We no longer need to set noninteractive to 1 in
non-termios build. The flag no longer exists.
(lino_copy, lino_cleanup): Avoid referencing nonexistent
members in non-termios build.
(lino_set_result): Another termios-only function.
* linenoise/linenoise.h (lino_set_result, lino_clear_screen,
lino_set_multiline, lino_get_multiline, lino_set_selinclusive,
lino_get_selinculsive, lino_set_noninteractive,
lino_get_noninteractive, lino_atom_cb_t, lino_set_atom_cb):
Declare only in termios build.
* parser.c (repl): Add #if HAVE_TERMIOS to avoid using
linenoise features not available in non-termios build, and to
remove any variables that thus become unused.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 43 | ||||
-rw-r--r-- | linenoise/linenoise.h | 4 |
2 files changed, 41 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; diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h index bc72eaa7..4ad3ce64 100644 --- a/linenoise/linenoise.h +++ b/linenoise/linenoise.h @@ -120,6 +120,7 @@ int lino_hist_set_max_len(lino_t *, int len); int lino_hist_save(lino_t *, const wchar_t *filename, int new_only); int lino_hist_load(lino_t *, const wchar_t *filename); int lino_have_new_lines(lino_t *); +#if HAVE_TERMIOS void lino_set_result(lino_t *, wchar_t *); /* takes ownership of malloced mem; modifies it */ int lino_clear_screen(lino_t *); void lino_set_multiline(lino_t *, int ml); @@ -128,10 +129,13 @@ void lino_set_selinclusive(lino_t *, int si); int lino_get_selinculsive(lino_t *); void lino_set_noninteractive(lino_t *, int ni); int lino_get_noninteractive(lino_t *); +#endif void lino_enable_noninteractive_prompt(lino_t *, int enable); +#if HAVE_TERMIOS typedef wchar_t *lino_atom_cb_t(lino_t *, const wchar_t *line, int n, void *ctx); void lino_set_atom_cb(lino_t *, lino_atom_cb_t *, void *ctx); +#endif typedef int lino_enter_cb_t(const wchar_t *line, void *ctx); void lino_set_enter_cb(lino_t *, lino_enter_cb_t *, void *ctx); |