|
|
Line 29: |
Line 29: |
| |} | | |} |
| </blockquote><!-- Notes --> | | </blockquote><!-- Notes --> |
|
| |
| = return values =
| |
| <blockquote>
| |
| Dialog saves it's result to stderr by default.
| |
| You can change this using the <code>--stdout</code> parameter.
| |
|
| |
| <source lang="bash">
| |
| VAR=$(dialog --menu 'Choose' 10 10 10 \
| |
| 0 apples \
| |
| 1 oranges \
| |
| 2 kiwis)
| |
| </source>
| |
|
| |
| See [https://askubuntu.com/questions/491509/how-to-get-dialog-box-input-directed-to-a-variable stack overflow] for details of saving dialog results to a variable.
| |
|
| |
| This is ackward. Bash does not support return codes other than 0 or 1.
| |
| Dialog, by default outputs it's result on stderr (so that it can be redirected into a file then read).
| |
| To skip the ackward in between step, you can do this:
| |
|
| |
| <syntaxhighlight lang="bash">
| |
| ## __NOTE__: the backslashes are mandatory here
| |
| result=$( \
| |
| dialog --title "Create Directory" \
| |
| --inputbox "Enter the directory name:" 8 40 \
| |
| 3>&1 1>&2 2>&3 3>&- \
| |
| )
| |
| echo $result
| |
| </syntaxhighlight>
| |
| </blockquote><!-- return values -->
| |
|
| |
| = components =
| |
| <blockquote>
| |
| == MessageBox ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| dialog --title 'Message' --msgbox 'Hello, world!' 5 20
| |
| </syntaxhighlight>
| |
| </blockquote><!-- MessageBox -->
| |
|
| |
| == Yes/No Prompt ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| dialog --title "Message" --yesno "Are you having\ fun?" 6 25
| |
| </syntaxhighlight>
| |
| </blockquote><!-- Yes/No Prompt -->
| |
|
| |
| == Input Box ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| # dialog --inputbox text width height
| |
| dialog --inputbox "Enter your name:" 8 40 2>answer
| |
| </syntaxhighlight>
| |
| </blockquote><!-- Input Box -->
| |
|
| |
| == Menu ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| ## dialog --menu <text> <height> <width>
| |
| dialog --menu "Choose one:" \
| |
| 10 30 3 `#height width menu-height` \
| |
| 0 red \
| |
| 1 green\
| |
| 2 blue
| |
| </syntaxhighlight>
| |
|
| |
| Here's a real example
| |
| <source lang="bash">
| |
| colourschemes=(soda hybrid diokai)
| |
| choices=""
| |
|
| |
| for i in ${!colourschemes[@]} ; do
| |
| choices+=" $i ${colourschemes[$i]}"
| |
| done
| |
|
| |
| result=$(eval "$dialog --menu Choose 10 10 3 $choices --stdout")
| |
| </source>
| |
| </blockquote><!-- Menu -->
| |
|
| |
| == Gauge (progressbar) ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| # reads/displays percentage on STDIN until EOF
| |
| for (( i=0; $i<100; i++ )); do
| |
| echo "$i"
| |
| sleep 0.2
| |
| done | dialog --gauge foo 10 100
| |
| </syntaxhighlight>
| |
| </blockquote><!-- Gauge (progressbar) -->
| |
|
| |
| == Calendar ==
| |
| <blockquote>
| |
| <syntaxhighlight lang="bash">
| |
| dialog --calendar \
| |
| "title" `# title` \
| |
| 1 80 `# width/height` \
| |
| 20 10 2020 `# (opt) day/month/year`
| |
| </syntaxhighlight>
| |
| </blockquote><!-- Calendar -->
| |
| </blockquote><!-- components -->
| |