File: dialog

package info (click to toggle)
modconf 0.2.48
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 548 kB
  • ctags: 64
  • sloc: sh: 795; perl: 279; makefile: 119
file content (119 lines) | stat: -rwxr-xr-x 2,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Whiptail functions for modconf

# (c) 2000 Software in the Public Interest
# Maintainer: Randolph Chung <tausq@debian.org> and debian-boot@lists.debian.org

# Derived from:
# Shell interface to "dialog"
# Bruce Perens, November 1995
# This is free software under the GNU General Public License.

export DIALOG_COMMAND=whiptail
#test -x /usr/bin/dialog && export DIALOG_COMMAND=dialog
# dialog breaks on zero-arguments

ttydev=${ttydev:-/dev/tty}

# Global options
#  The variable $BACKTITLE specifies the back title.
#  The variable $DIALOG_OPTIONS, initialized here to --clear, provides
#  options you want on the command line of each dialog invocation.
#  The variable $DIALOG_TEST can be set to "echo" to see the calls
#  to dialog without executing them.

DIALOG_OPTIONS=""
BACKTITLE=""

# Make any dialogue box, with default settings and backtitle from
# $BACKTITLE in the environment.
#
# dialog --type arg arg ...
#
dialogBox () {
  local type="$1"
  shift
  local title=""
  local backtitle=""
  local result
  local status

  local text="$1"
  shift

  if [ $# -ge 1 ]; then
    title="$1"
    shift
  fi

  if [ -n "$BACKTITLE" ]; then
    backtitle="$BACKTITLE"
  fi

  # do not confuse whiptail with different LC_* vars, we do not need
  # LC_MESSAGES at this point anyways
  unset LC_MESSAGES || true
  $DIALOG_TEST $DIALOG_COMMAND $DIALOG_OPTIONS --title "$title" \
     --backtitle "$backtitle" "$type" "$text " 0 0 "$@" 2>&1 1>$ttydev
  
  return $?
}

# Display a file.
#
# fileBox filename [title]
#
fileBox () {
  dialogBox --textbox "$1" "$2"
}

msgBox () {
  dialogBox --msgbox "$1" "$2"
}

infoBox () {
  dialogBox --infobox "$1" "$2"
}

yesNoBox () {
  dialogBox --yesno "$1" "$2"
  return $?
}

inputBox () {
  dialogBox --inputbox "$1" "$2" "$3" "$4"
  return $?
}

# menu text title tag1 item1 ...
menu () {
  local text="$1"
  shift
  local title="$1"
  shift
  dialogBox --menu "$text" "$title" 0 "$@"
  return $?
}

# menu text title tag1 item1 status1 ...
checklist () {
  local text="$1"
  shift
  local title="$1"
  shift
  dialogBox --checklist "$text" "$title" 0 "$@"
  return $?
}

# menu text title tag1 item1 status1 ...
radiolist () {
  local text="$1"
  shift
  local title="$1"
  shift
  dialogBox --radiolist "$text" "$title" 0 "$@"
  return $?
}

# Local Variables:
# mode: shell-script
# End: