Create a countdown dialog box for linux terminal?

How do I create a dialog widget for the Linux console (not X, but the "terminal" console) that will show a countdown in seconds next to the widgets, which could be a menu list or a textbox?

Ideally, this could be a stand-alone program, such as a dialog, that provides options to control its behavior.

When the countdown reaches 0, the selected widget value is returned. Can be a default if the person is not present (or the person prefers the default). Boot loaders like grub and lilo can do this already, to a great extent. I looked at the dialog page and could not find this function.

Tried so far:

dialog --timeout 30 --menu 'Menu Title' 20 60 3 'A' 'Choose A' 'B' 'Choose B' 'C' 'Choose C'

is close but does not show a 30 second timer.

dialog --pause 'Hurry!' 10 60 30 --

shows a message and ok / cancel with a timer running, but is only interstitial and not user input.

You can concatenate multiple lines like this:

dialog --menu 'Menu Title' 10 60 3 'A' 'Choose A' 'B' 'Choose B' 'C' 'Choose C' --pause 'Hurry up' 10 60 30 

      

but this shows the widgets in sequence, not combined on the same page. Here, after answering a menu without a timer, you get a message with a timer.

+2


source to share


3 answers


I believe Ncurses is what you are looking for.



+1


source


To use the dialog, I solved a similar problem by splitting it into two dialog boxes. First, a dialog box pops up with a default (and optionally an alternate selection) displayed on the screen, and this has a countdown timer. User can press esc or press "Cancel" to change the parameter, or the countdown will reach 0 and the program will continue with the default settings. If the user accesses the escape, a second dialog box appears that allows editing the parameters. I didn't want to add additional software to our deb-live / clonezilla OS build, so I had to find a way with a dialog.

dialog --title Some options to choose from, showing default --pause "\n\n Do you accept these options?:  \n  ${options_in_nice_format_for_display}" 20 60 5
[ $? -ne 0 ] && EDIT_IP=true || EDIT_IP=false

if ${EDIT_IP}; then
    dialog --editbox ${MY_OPTIONS_FILE} 20 60 2> ${EDITED_OPTIONS_FILE}
fi

      



For an even better solution (which I used, but didn't want to add extra code here), you can add a boolean conditional while loop and allow the changes to be repeated until the user is satisfied.

+3


source


I suggest you read the man page dialog

. You've already done that, you say? Then what's wrong:

- pause text height width seconds

The pause window displays the meter at the bottom of the window. The indicator shows how many seconds are left until the end of the pause. The pause ends when the timeout is reached, or the user presses the OK button (OK status), or the user presses the CANCEL button or the Esc key.

+2


source







All Articles