Jump to content

Dialog

From Squishu Wiki

General

  • dialog lets you present various graphical boxes
  • dialog returns when the user made some input and the result can be found either from the exit status or if text was entered, by retrieving it from the standard error stream

Hello World

  • dialog --msgbox "Hello Douches" 9 18
    • 9 18 refer to text height and width

types of dialogs

  • --checklist
  • --infobox
  • --inputbox
  • --menu
  • --msgbox
  • --radiolist
  • --textbox
  • --yesno
  • Each of these have different params that can be used with them
  • --title provides a title for any of the boxes
  • --clear clears it

capturing the output

  • To get textural output or selections, capture the stderr stream by directing it to a temporary file. Process the output file afterwards
  • To get the result of Yes/No, just look at the exit code
    • 0 for success
    • 1 for failure

Examples

  • dialog --title "Check Me" --checklist "Pick Numbers" 15 25 3 1 "one" "off" 2 "two" "on" 3 "three" "off"
    • Check Me is the title
    • Pick Numbers is the prompt message
    • size is 15 lines high by 25 characters wide
    • 3 lines will be used for the menu
  • each menu item has 3 values
    • bullet number
    • text
    • status

Sample

#/bin/bash
dialog --title "Questions" --msgbox "Take a survey" 9 18

display --title "Confirm" --yesno "Are you willing to take a survey" 9 18
if [ $? != 0 ]; then
  # $? checks the exit code for yes/0 and exits them if they typed no
  dialog --infobox "Thanks anyways" 5 20
  sleep 2
  dialog --clear
  exit 0 
fi

display --title "Questionnaire" --inputbox "Please enter your name" 9 30 2>_1.txt
Q_NAME=$(cat _1.txt)
# You enter your name and it's written to stderr and sent to the file _1.txt which is then assigned to a variable

dialog --menu "$Q_NAME, what music do you like" 15 30 4 1 "Classical" 2 "Jazz" 3 "Rock" 4 "Other" 2>_1.txt
Q_MUSIC=$(cat _1.txt)

if { $Q_MUSIC" == "1" ]; then
  dialog --msgbox "You have sublime taste" 12 25
fi

sleep 5
dialog --clear
exit 0