summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-08-03 07:09:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-08-03 07:09:59 -0700
commit70a9ef01f022982241f80fe1eac19930aa597507 (patch)
tree67b38122140ef47de335564e6815770e3fa033be
parentd4d626c256dd5147d308e609a9b6c341d8e0a02b (diff)
downloadtxr-70a9ef01f022982241f80fe1eac19930aa597507.tar.gz
txr-70a9ef01f022982241f80fe1eac19930aa597507.tar.bz2
txr-70a9ef01f022982241f80fe1eac19930aa597507.zip
listener: print prompts in plain mode if stdin is tty.
* linenoise/linenoise.c (linenoise): Force the printing of prompts if the input file descriptor is a tty. * txr.1: Documentation updated.
-rw-r--r--linenoise/linenoise.c7
-rw-r--r--txr.113
2 files changed, 9 insertions, 11 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 266542c1..256553d4 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -2533,12 +2533,13 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
int count;
int ifd = lino_os.fileno_fn(ls->tty_ifs);
- if ( ls->noninteractive || !isatty(ifd)) {
+ if (ls->noninteractive || !isatty(ifd)) {
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));
- if (ls->show_prompt) {
+ if (show_prompt) {
while (condensed_prompt > prompt &&
(*condensed_prompt == 0 || *condensed_prompt == ' '))
{
@@ -2549,7 +2550,7 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
for (;;) {
size_t nlen;
- if (ls->show_prompt)
+ if (show_prompt)
lino_os.puts_fn(ls->tty_ofs, ret ? condensed_prompt : prompt);
/* Not a tty: read from file / pipe. */
diff --git a/txr.1 b/txr.1
index ab260a57..280aff16 100644
--- a/txr.1
+++ b/txr.1
@@ -82533,16 +82533,12 @@ incrementing the prompt number. The
command prints just the current prompt number, followed by a newline,
without incrementing the number.
-The
+In plain mode, 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.
+the continuation lines of an incomplete expression. The printing of prompts
+is automatically enabled if the input device is an interactive terminal.
None of these prompt-related commands are entered into the history.
@@ -82558,7 +82554,8 @@ the listener operates in
It reads input without providing any editing features: no completion,
history recall, selection, or copy and paste. Only the line editing
features provided by the operating system are available.
-No prompts appear; however, there is still an incrementing counter,
+Prompts appear if standard input is an interactive terminal, or
+if explicitly enabled. There is still an incrementing counter,
and the numbered variables
.codn *1 ,
.codn *2 ,