Sample Header Ad - 728x90

How to get user input in dialog --tailboxbg --gauge?

1 vote
0 answers
95 views
I have a script I run on a macOS machine, where I wish to show a gauge bar and tail the output from the script itself at the same time. I currently use this command, and it works well:
`
#!/bin/bash

TERMINAL_COLS=$(tput cols)
TERMINAL_ROWS=$(tput lines)

(while true ; do
     df /Volumes/Backup/ | tail -1 | awk '{print int($3/($3+$4)*100)}'
     sleep 1
 done | dialog --no-shadow --begin 7 0 \
               --tailboxbg /tmp/backup.log $(( $TERMINAL_ROWS - 7 )) $TERMINAL_COLS \
               --and-widget --begin 0 0 \
               --gauge 'Backup volume usage' 7 $TERMINAL_COLS) &

exec >> /tmp/backup.log
exec 2>&1

...rest of script...
` This runs dialog with a tailboxbg widget, which tails a log file. And it shows the output of the df loop in a gauge widget. Afterwards, the STDOUT and STDERR of the script itself is redirected into the logfile. Again, this works perfectly well: the script runs as usual, its output is displayed in the tailboxbg widget, and the gauge shows the used capacity of the volume as emitted by df. The only issue is that dialog now has no access to the real STDIN (i.e., key presses / terminal) anymore. This means that I cannot use cursor keys to scroll through the tailboxbg widget, or interact with dialog in any other way. Reading the man page, I do not see a way to get the percentage values to the gauge widget in any other way. Specifically, it says for the --input-fd option: --input-fd fd Read keyboard input from the given file descriptor. Most dialog scripts read from the standard input, but the gauge widget reads a pipe (which is always standard input). [...] Another idea would be to alias the real STDIN and give it to the tailboxbg via --input-fd. The following didn't work though (nothing changed compared to the previous behaviour):
`
...

exec 5<&0

(while true ; do
     df /Volumes/Backup/ | tail -1 | awk '{print int($3/($3+$4)*100)}'
     sleep 1
 done | dialog --input-fd 5 --no-shadow --begin 7 0 --tailboxbg /tmp/backup.log $(( $TERMINAL_ROWS - 7 )) $TERMINAL_COLS --and-widget --begin 0 0 --gauge 'Backup volume usage' 7 $TERMINAL_COLS) &

...
` The optimum would be if --gauge allowed to specify an input file instead of always reading STDIN as specified in the man page, but that's not the way it works. So... is there a way to forward the "real" STDIN (i.e. user input) to the tailboxbg widget, but still pipe the output from the fd loop to the gauge widget at the same time?
Asked by AnoE (947 rep)
Apr 18, 2024, 11:09 AM
Last activity: Apr 18, 2024, 11:22 AM