slitaz-tools view tinyutils/tazdialog @ rev 244

bootfloppybox: no /boot in liveCD, use tazpkg get-install --forced for gpxe ... in text mode too
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 16 21:39:27 2008 +0000 (2008-07-16)
parents 37ac5a2b6e88
children 981e48565c3a
line source
1 #!/bin/sh
2 # tazdialog - SliTaz GNU/Linux dialog wrapper to gtkdialog.
3 #
4 # (C) 2008 SliTaz - GNU General Public License v3.
5 #
6 # Author : Pascal Bellard <pascal.bellard@slitaz.org>
7 #
9 toutf8()
10 {
11 echo -e $1 | sed -e 's/\\Z.//g' | tr 'àâäçéèêëîïûü' 'aaaceeeeiiuu'
12 }
14 if [ -z "$XAUTHORITY" ]; then
15 [ -n "$TEXTDIALOG" ] || TEXTDIALOG="dialog"
16 export DIALOG=$TEXTDIALOG
17 exec $TEXTDIALOG "$@"
18 else
19 title=""
20 backtitle=""
21 lines="10"
22 cols="10"
23 [ -n "$ICON" ] || ICON="applications-other"
24 buttonok=""
25 buttoncancel=""
26 buttonextra=""
27 yeslabel="ok"
28 nolabel="cancel"
29 extralabel="rename"
30 gauge=""
31 inputbox=""
32 default=""
33 buttonhelp=""
34 checklist=""
35 menu=""
36 textbox=""
37 radiolist=""
38 fselect=""
39 while [ -n "$1" ]; do
40 case "$1" in
41 --title) title="$2"; shift 2;;
42 --backtitle) backtitle="$2"; shift 2;;
43 --clear|--colors) shift;;
44 --yes-label) yeslabel="$2"; shift 2;;
45 --no-label) nolabel="$2"; shift 2;;
46 --extra-label) extralabel="$2"; shift 2;;
47 --extra-button) buttonextra="1"; shift;;
48 --help-button) buttonhelp="1"; shift;;
49 --msgbox) msgbox="$2"; lines="$3"; cols="$4"
50 buttonok="1"; break;;
51 --yesno) msgbox="$2"; lines="$3"; cols="$4"
52 buttonok="1"; buttoncancel="1"; break;;
53 --gauge) msgbox="$2"; lines="$3"; cols="$4"
54 percent="$5"; gauge="1"; break;;
55 --inputbox) msgbox="$2"; lines="$3"; cols="$4"; default="$5"
56 buttonok="1"; buttoncancel="1"; inputbox="1"; break;;
57 --checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
58 buttonok="1"; checklist="1"; shift 5; break;;
59 --menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
60 buttonok="1"; buttoncancel="1"
61 menu="1"; shift 5; break;;
62 --textbox) textbox="$2"; lines="$3"; cols="$4"
63 buttonok="1"; break;;
64 --radiolist) textbox="$2"; lines="$3"; cols="$4"; inlines="$5"
65 buttonok="1"; buttoncancel="1"
66 radiolist="1"; shift 5; break;;
67 --fselect) fselect="$2"; lines="$3"; cols="$4"
68 buttonok="1"; buttoncancel="1"; break;;
69 *) echo "Unknown arg $1"; return 255;;
70 esac
71 done
72 fi
73 msgbox="$(toutf8 "$msgbox")"
74 textbox="$(toutf8 "$textbox")"
75 title="$(toutf8 "$title")"
76 backtitle="$(toutf8 "$backtitle")"
77 yeslabel="$(toutf8 "$yeslabel")"
78 nolabel="$(toutf8 "$nolabel")"
79 extralabel="$(toutf8 "$extralabel")"
80 default="$(toutf8 "$default")"
81 BOX="<window"
82 [ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\""
83 [ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\""
84 BOX="$BOX>
85 <vbox>
86 "
87 [ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\">
88 <label>\"<b>$title</b>\" </label>
89 </text>
90 "
91 [ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" use-markup=\"true\">
92 <label> \"$msgbox\" </label>
93 </text>
94 "
95 [ -n "$gauge" ] && BOX="$BOX <progressbar>
96 <input>while read data; do echo \$data; done</input>
97 <action type=\"exit\">0</action>
98 </progressbar>
99 "
100 [ -n "$default" ] && default="<default>$default</default>
101 "
102 [ -n "$inputbox" ] && BOX="$BOX <entry>
103 $default<variable>OUTPUT</variable>
104 </entry>
105 "
106 #[ -n "$textbox" ] && BOX="$BOX <text><input file width-chars=\"$cols\" \
107 #height=\"$lines\" wrap=\"true\">$textbox</input></text>"
108 [ -n "$textbox" ] && BOX="$BOX <text>
109 <input file wrap=\"true\">$textbox</input>
110 </text>
111 "
112 [ -n "$menu" ] && BOX="$BOX <list>
113 $(while [ -n "$1" ]; do
114 echo " <item>$1 $2</item>
115 "
116 shift 2
117 done) <variable>LIST</variable>
118 </list>
119 "
120 [ -n "$radiolist" ] && BOX="$BOX$(
121 i=0; while [ -n "$1" ]; do
122 [ "$3" = "on" ] && c=" active=\"true\"" || c=""
123 echo " <radiobutton$c>
124 <label>$1 $2</label>
125 <variable>CHECK$i</variable>
126 </radiobutton>
127 "
128 i=$(($i+1))
129 shift 3
130 done)"
131 [ -n "$checklist" ] && BOX="$BOX $(
132 i=0; while [ -n "$1" ]; do
133 [ "$3" = "on" ] && c=" active=\"true\"" || c=""
134 echo " <checkbox$c>
135 <label>$1 $2</label>
136 <variable>CHECK$i</variable>
137 </checkbox>
138 "
139 i=$(($i+1))
140 shift 3
141 done)"
142 [ -n "$fselect" ] && BOX="$BOX <hbox>
143 <entry>
144 <variable>OUTPUT</variable>
145 </entry>
146 <button>
147 <input file stock=\"gtk-open\"></input>
148 <variable>FILE_BROWSE</variable>
149 <action type=\"fileselect\">OUTPUT</action>
150 </button>
151 </hbox>
152 "
153 [ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel="
154 <label>$yeslabel</label>"
155 [ "$nolabel" = "cancel" ] && nolabel="" || nolabel="
156 <label>$nolabel</label>"
157 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX <hbox>"
158 [ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel
159 <action type=\"exit\">0</action>
160 </button>
161 "
162 [ -n "$buttonextra" ] && BOX="$BOX <button>
163 <label>$extralabel</label>
164 <input file icon=\"forward\"> </input>
165 <action type=\"exit\">3</action>
166 </button>
167 "
168 [ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel
169 <action type=\"exit\">1</action>
170 </button>
171 "
172 [ -n "$buttonhelp" ] && BOX="$BOX <button help>
173 <action type=\"exit\">2</action>
174 </button>
175 "
176 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox>
177 "
178 BOX="$BOX </vbox>
179 </window>
180 "
181 export BOX
182 status=$(if [ -n "$gauge" ]; then
183 ([ -n "$percent" ] && echo $percent
184 while read line; do
185 case "$line" in
186 [0-9]*) echo $line;;
187 *);;
188 esac
189 done ; echo 100) | gtkdialog --center --program=BOX
190 else
191 gtkdialog --center --program=BOX
192 fi 2> /dev/null | while read line; do
193 case "$line" in
194 *OUTPUT*) eval $line
195 echo "$OUTPUT" 1>&2 ;;
196 *CHECK*true*) line=${line%=*}; line=${line#CHECK}
197 [ $line -eq 0 ] || shift $((3 * $line))
198 echo -n "\"$1\" " 1>&2;;
199 *LIST=*) eval $line; set -- $LIST
200 echo "$1" 1>&2 ;;
201 *EXIT*abort*) echo 255;;
202 *EXIT*) eval $line
203 echo $EXIT ;;
204 esac
205 done)
206 exit $status