bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix 'flash' for Bash


From: Harm te Hennepe
Subject: [PATCH] Fix 'flash' for Bash
Date: Wed, 11 Sep 2024 18:53:05 +0200

At the moment the time-delay of 100ms for 'flash' (as specified in my
terminfo entry) doesn't work correctly with Bash/Readline (`set
bell-style visible`). It makes use of `tputs`.

A strace shows that the time-delay isn't happening at the right moment:
```
strace: Process 3872344 attached
read(0, "\10", 1)                       = 1
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=100000000},
0x7ffca150b340) = 0
write(2, "\33[?5h\33[?5l", 10)          = 10
```

In v6_2_20201128 a `fflush(stdout)` was added for applications using
low-level calls [1]

Unfortunately, Bash uses stderr /and/ sets it to buffered. I suggest
fflush'ing stderr as well. With the patch below applied, the flash
works as expected again:
```
strace: Process 3876152 attached
read(0, "\10", 1)                       = 1
write(2, "\33[?5h", 5)                  = 5
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=100000000},
0x7ffdf8a19110) = 0
write(2, "\33[?5l", 5)                  = 5
```

I guess a better solution would be to have a `tputs2`, which also
accepts a callback for flushing the stream.
But, as this has already been broken since at least 2006 (I started a
VM with an Ubuntu 6.06 live cd), and probably never worked, I think
the incentive for implementing that would be low.

On a sidenote, as `SP_PARM->_ofd > 0`, shouldn't [2] be `fflush(SP_PARM->_ofd)`?

[1] 
https://github.com/ThomasDickey/ncurses-snapshots/blob/21c551ae1d2aa970ceae868fffd80922f6263565/NEWS#L53
[2] 
https://github.com/ThomasDickey/ncurses-snapshots/blob/a480458efb0662531287f0c75116c0e91fe235cb/ncurses/tinfo/lib_tputs.c#L154

diff --git a/ncurses/tinfo/lib_tputs.c b/ncurses/tinfo/lib_tputs.c
index f834532..10ccb3f 100644
--- a/ncurses/tinfo/lib_tputs.c
+++ b/ncurses/tinfo/lib_tputs.c
@@ -150,12 +150,14 @@ NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_DCL0)
                }
            }
        } else if (SP_PARM->out_buffer == 0) {
-           TR(TRACE_CHARPUT, ("flushing stdout"));
+           TR(TRACE_CHARPUT, ("flushing stdout/stderr"));
            fflush(stdout);
+           fflush(stderr);
        }
     } else {
-       TR(TRACE_CHARPUT, ("flushing stdout"));
+       TR(TRACE_CHARPUT, ("flushing stdout/stderr"));
        fflush(stdout);
+       fflush(stderr);
     }
     if (SP_PARM != 0)
        SP_PARM->out_inuse = 0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]