Currently playing around with the dialog command and I have noticed that when I press Shift-Tab or press ESC, the execution immediately exits and I am back on the command prompt. Since this is not a signal, I can't trap and discard it, so how would I "trap"/capture this escape and discard it so that the only way to exit the dialog is through whatever widget/box I set up?
Note: I have already researched why the combination of Shift and Tab triggers the escape. It is not a single keystroke and the solutions I have found only work when the input expected is a single keyboard stroke. Dialog does not have documentation on this topic and anything outside of its man page seems to be lacking.
答案1
Shift+Tab is usually a back-tab on terminals that you are likely to use.
The manual page section KEY BINDINGS comments that dialog's key bindings can be curses keys
It may be any of the names derived from
curses.h
, e.g., "HELP" from "KEY_HELP".
and in the section Built-in Bindings explains that the --trace
option can be used to show the built-in bindings:
This manual page does not list the key bindings for each widget, because that detailed information can be obtained by running
dialog
. If you have set the--trace
option,dialog
writes the key-binding information for each widget as it is registered.
As an example, it shows how to bind TAB and BTAB (the name derived from curses KEY_BTAB
):
bindkey formfield TAB form_NEXT
bindkey formbox TAB form_NEXT
bindkey formfield BTAB form_prev
bindkey formbox BTAB form_prev
KEY_BTAB
(see getch manual page) is the back-tab key.
In terminfo, that is named kcbt
:
key_btab kcbt kB back-tab key
You can see a terminal description using infocmp
.
If you happen to have set TERM to a terminal description which does not define kcbt
, then (because it is usually an escape sequence), curses will not recognize it, and will pass the individual bytes to the application (dialog). dialog uses the ASCII escape character (ESC
) to cancel the current widget. A shell script can check for this by inspecting the exit-status. The ENVIRONMENT section documents environment variables which can be used to customize the exit-status:
Define any of these variables to change the exit code on Cancel (1), error (-1),
ESC
(255), Extra (3), Help (2), Help with --item-help (2), or OK (0). Normally shell scripts cannot distinguish between -1 and 255.