aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/build/wine/dialog.sh
blob: 671d03e061f3e530950a80dae1a5b60a12b21e83 (plain) (blame)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env sh

# Usage:
# dailog.sh [tui|gui] [--infobox|--messagebox|--yesno|--gauge] title message
# WARNING: no error checking is done

fake_dialog () {
	case "$2" in
		--infobox)
			echo ""
			echo "$3"
			echo "$4"
			echo ""
			;;
		--msgbox)
			echo ""
			echo "$3"
			echo "$4"
			read -p "Press [Enter] key to continue ... \$ " DIALOG_RESULT
			echo ""
			;;
		--yesno)
			while true ; do
				echo ""
				echo "$3"
				echo "$4"
				read -p "([yes], no) \$ " DIALOG_RESULT
				echo ""
				case "x$DIALOG_RESULT" in
					xno)
						DIALOG_RESULT="n"
						break
						;;
					xNO)
						DIALOG_RESULT="n"
						break
						;;
					xyes)
						DIALOG_RESULT="y"
						break
						;;
					xYES)
						DIALOG_RESULT="y"
						break
						;;
					x)
						DIALOG_RESULT="y"
						break
						;;
					*)
						;;
				esac
			done
			case "$DIALOG_RESULT" in
				n)
					(exit 1)
					;;
				y)
					(exit 0)
					;;
				*)
					(exit 0)
					;;
			esac
			;;
		--textbox)
			echo ""
			echo "$3"
			if command -v "less" 2>/dev/null 1>/dev/null ; then
				less "$4"
			else
				if command -v "more" 2>/dev/null 1>/dev/null ; then
					more "$4"
				else
					cat "$4"
					read -p "Press [Enter] key to continue ... \$ " DIALOG_RESULT
				fi
			fi
			echo ""
			;;
		*)
			echo "$4"
			;;
	esac
}

fake_progress () {
	echo ""
	echo "$3"
	echo "$4"
	echo -n "0%..."
	while IFS='' read -r line ; do
		if [ '(' "$line" -gt 1 ')' -a '(' "$line" -lt 100 ')' ]; then
	    echo -n "$line%..."
		fi
	done
	echo -n "100%"
	echo ""
	echo ""
}

if [ "$2" = "--gauge" ]; then
  if [ "$1" = "tui" ]; then
		DIALOG_LIST="dialog whiptail gdialog xdialog fake_progress"
	else
		DIALOG_LIST="zenity gdialog xdialog dialog whiptail fake_progress"
	fi
	for d in $DIALOG_LIST ; do
		if [ "$d" = "fake_progress" ]; then
			fake_progress "tui" "$2" "$3" "$4"
			exit $?
		else
			if command -v "$d" 2>/dev/null 1>/dev/null ; then
				if [ "$d" = "zenity" ]; then
					exec $d --title "$3" --auto-close --progress "--text=$4" 0 0 0
				else
					exec $d --title "$3" "$2" "$4" 0 0 0
				fi
			fi
		fi
	done
else
  if [ "$1" = "tui" ]; then
		DIALOG_LIST="dialog whiptail gdialog xdialog fake_dialog"
	else
		DIALOG_LIST="gdialog xdialog dialog whiptail fake_dialog"
	fi
	for d in $DIALOG_LIST ; do
		if [ "$d" = "fake_dialog" ]; then
			fake_dialog "tui" "$2" "$3" "$4"
			exit $?
		else
			if command -v "$d" 2>/dev/null 1>/dev/null ; then
				exec $d --title "$3" "$2" "$4" 0 0
			fi
		fi
	done
fi