summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--linenoise/linenoise.c19
-rw-r--r--linenoise/linenoise.h1
-rw-r--r--parser.c4
-rw-r--r--txr.114
4 files changed, 36 insertions, 2 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index c25014cf..266542c1 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -137,6 +137,7 @@ 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. */
+ int show_prompt; /* Show prompting in non-interactive mode. */
struct lino_undo *undo_stack;
lino_error_t error; /* Most recent error. */
};
@@ -207,6 +208,11 @@ int lino_get_noninteractive(lino_t *ls)
return ls->noninteractive;
}
+void lino_enable_noninteractive_prompt(lino_t *ls, int enable)
+{
+ ls->show_prompt = enable;
+}
+
void lino_set_atom_cb(lino_t *l, lino_atom_cb_t *cb, void *ctx)
{
l->atom_callback = cb;
@@ -2530,9 +2536,22 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
if ( ls->noninteractive || !isatty(ifd)) {
wchar_t *ret = 0;
size_t len = 0, i;
+ const wchar_t *condensed_prompt = prompt + wcslen(prompt);
+
+ if (ls->show_prompt) {
+ while (condensed_prompt > prompt &&
+ (*condensed_prompt == 0 || *condensed_prompt == ' '))
+ {
+ condensed_prompt--;
+ }
+ }
for (;;) {
size_t nlen;
+
+ if (ls->show_prompt)
+ lino_os.puts_fn(ls->tty_ofs, ret ? condensed_prompt : prompt);
+
/* Not a tty: read from file / pipe. */
if (lino_os.getl_fn(ls->tty_ifs, ls->data, nelem(ls->data)) == 0) {
ls->error = (lino_os.eof_fn(ls->tty_ifs) ? lino_eof : lino_ioerr);
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index 151ee99c..7fef68d9 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -124,6 +124,7 @@ 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 *);
+void lino_enable_noninteractive_prompt(lino_t *, int enable);
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);
diff --git a/parser.c b/parser.c
index 4140f6e6..1653f596 100644
--- a/parser.c
+++ b/parser.c
@@ -1474,6 +1474,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
val quit_k = intern(lit("quit"), keyword_package);
val read_k = intern(lit("read"), keyword_package);
val prompt_k = intern(lit("prompt"), keyword_package);
+ val prompt_on_k = intern(lit("prompt-on"), keyword_package);
val p_k = intern(lit("p"), keyword_package);
val save_k = intern(lit("save"), keyword_package);
val counter_sym = intern(lit("*n"), user_package);
@@ -1599,6 +1600,9 @@ val repl(val bindings, val in_stream, val out_stream, val env)
} else if (form == prompt_k) {
pprinl(prompt, out_stream);
counter = prev_counter;
+ } else if (form == prompt_on_k) {
+ lino_enable_noninteractive_prompt(ls, 1);
+ counter = prev_counter;
} else if (form == p_k) {
pprinl(prev_counter, out_stream);
counter = prev_counter;
diff --git a/txr.1 b/txr.1
index 12b64512..ab260a57 100644
--- a/txr.1
+++ b/txr.1
@@ -82533,8 +82533,18 @@ incrementing the prompt number. The
command prints just the current prompt number, followed by a newline,
without incrementing the number.
-These comments are useful in plain mode, in which no prompts are
-printed. See Plain Mode below.
+The
+.code :prompt-on
+command enables the printing of prompts. The full prompt is printed before
+reading each new expression. An abbreviated prompt is printed before reading
+the continuation lines of an incomplete expression.
+
+These commands are useful in plain mode, in which no prompts are
+printed by default. See Plain Mode below. The
+.code :prompt-on
+command only has an effect in plain mode.
+
+None of these prompt-related commands are entered into the history.
.SS* Plain Mode