slitaz-tools view tinyutils/tazdialog @ rev 195

Added tag 2.4 for changeset 2b9d7c28e30a
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 16 00:57:36 2008 +0200 (2008-05-16)
parents 92aedc898747
children 39e31613e665
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 $TEXTDIALOG "$@"
18 return $?
19 else
20 title=""
21 backtitle=""
22 lines="10"
23 cols="10"
24 [ -n "$ICON" ] || ICON="applications-other"
25 buttonok=""
26 buttoncancel=""
27 buttonextra=""
28 yeslabel="ok"
29 nolabel="cancel"
30 extralabel="rename"
31 gauge=""
32 inputbox=""
33 default=""
35 buttonhelp=""
36 checklist=""
37 menu=""
38 textbox=""
39 args=""
40 while [ -n "$1" ]; do
41 case "$1" in
42 --title) title="$2"; shift 2;;
43 --backtitle) backtitle="$2"; shift 2;;
44 --clear|--colors) shift;;
45 --yes-label) yeslabel="$2"; shift 2;;
46 --no-label) nolabel="$2"; shift 2;;
47 --extra-label) extralabel="$2"; shift 2;;
48 --extra-button) buttonextra="1"; shift;;
49 --help-button) buttonhelp="1"; shift;;
50 --msgbox) msgbox="$2"; lines="$3"; cols="$4"
51 buttonok="1"; break;;
52 --yesno) msgbox="$2"; lines="$3"; cols="$4"
53 buttonok="1"; buttoncancel="1"; break;;
54 --gauge) msgbox="$2"; lines="$3"; cols="$4"
55 percent="$5"; gauge="1"; break;;
56 --inputbox) msgbox="$2"; lines="$3"; cols="$4"
57 default="$5"
58 buttonok="1"; buttoncancel="1"
59 inputbox="1"; break;;
61 --checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
62 buttonok="1"; checklist="1"; shift 5; args="$@"; break;;
63 --menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5"
64 buttonok="1"; buttoncancel="1"
65 menu="1"; shift 5; args="$@"; break;;
66 --textbox) textbox="$2"; lines="$3"; cols="$4"
67 buttonok="1"; break;;
68 *) echo "Unknown arg $1"; return 255;;
69 esac
70 done
71 fi
72 msgbox="$(toutf8 "$msgbox")"
73 textbox="$(toutf8 "$textbox")"
74 BOX="<window"
75 [ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\""
76 [ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\""
77 BOX="$BOX> <vbox>"
78 [ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\"> \
79 <label>\"<b>$title</b>\" </label> </text>"
80 #[ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" \
81 #width-chars=\"$cols\" use-markup=\"true\"><label> \"$msgbox\" </label></text>"
82 [ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" \
83 use-markup=\"true\"><label> \"$msgbox\" </label></text>"
84 [ -n "$gauge" ] && BOX="$BOX <progressbar><input>while read data; do \
85 echo \$data; done</input><action type=\"exit\">0</action></progressbar>"
86 [ -n "$default" ] && default="<default>$default</default>"
87 [ -n "$inputbox" ] && BOX="$BOX <entry>$default<variable>OUTPUT</variable> \
88 </entry>"
89 #[ -n "$textbox" ] && BOX="$BOX <text><input file width-chars=\"$cols\" \
90 #height=\"$lines\" wrap=\"true\">$textbox</input></text>"
91 [ -n "$textbox" ] && BOX="$BOX <text><input file \
92 wrap=\"true\">$textbox</input></text>"
93 [ -n "$menu" ] && BOX="$BOX <list>$(
94 set -- $args | while [ -n "$1" ]; do
95 echo "<item>$1 $2</item>"
96 shift 2
97 done) <variable>LIST</variable> </list>"
98 [ -n "$checklist" ] && BOX="$BOX $(
99 i=0; set -- $args | while [ -n "$1" ]; do
100 [ "$3" = "on" ] && c=" active=\"true\"" || c=""
101 echo "<checkbox$c><label>$1 $2</label><variable>CHECK$i</variable></checkbox>"
102 i=$(($i+1))
103 shift 3
104 done)"
105 [ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel="<label>$yeslabel</label>"
106 [ "$nolabel" = "cancel" ] && nolabel="" || nolabel="<label>$nolabel</label>"
107 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX <hbox>"
108 [ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel \
109 <action type=\"exit\">0</action> </button>"
110 [ -n "$buttonextra" ] && BOX="$BOX <button><label>$extralabel</label> \
111 <input file icon=\"forward\"> </input> <action type=\"exit\">3</action> \
112 </button>"
113 [ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel \
114 <action type=\"exit\">1</action> </button>"
115 [ -n "$buttonhelp" ] && BOX="$BOX <button help> <action type=\"exit\">2\
116 </action> </button>"
117 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox>"
118 BOX="$BOX </vbox></window>"
119 export BOX
120 status=$(if [ -n "$gauge" ]; then
121 ( while read line; do
122 case "$line" in
123 [0-9]*) echo $line;;
124 *);;
125 esac
126 done ; echo 100) | gtkdialog --center --program=BOX
127 else
128 gtkdialog --center --program=BOX
129 fi 2> /dev/null | while read line; do
130 case "$line" in
131 *OUTPUT*) eval $line
132 echo "$OUTPUT" 1>&2 ;;
133 *CHECK*true*) line=${line%=*}; line=${line#CHECK}
134 set -- $args
135 [ $line -eq 0 ] || shift $(($line * 3))
136 echo -n "\"$1\" " 1>&2 ;;
137 *LIST=*) eval $line; set -- $LIST
138 echo "$1" 1>&2 ;;
139 *EXIT*abort*) echo 255;;
140 *EXIT*) eval $line
141 echo $EXIT ;;
142 esac
143 done)
144 exit $status