-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialog.sh
134 lines (112 loc) · 2.35 KB
/
dialog.sh
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
DIALOG="dialog --keep-tite --stdout"
function show_list ()
{
local title="$1"
local columns=" # $2"
local list="$3"
local extra="$4"
if [[ "$list" && "$extra" ]]
then
list=`echo -e "$list\n$extra"`
fi
if [[ -z "$list" && "$extra" ]]
then
list="$extra"
fi
echo -e "$list" > list
END=`cat list | wc -l`
for ((i=1;i<=END;i++)); do echo $i; done > nums
local id=`paste -d "\n" nums list | tr "\n" "\0" | xargs -0 $DIALOG --title "$title" --no-collapse --menu "$columns" 0 0 0`;
if [[ -z "$id" ]]
then
return 255
fi
local elem=`echo -e "$list" | sed "${id}q;d"`;
echo -e "$elem"
return $res
}
function get_password ()
{
title="$1"
msg="$2"
pin=`$DIALOG --title "$title" --passwordbox "$msg" 0 0 ""`;
res=$?
echo "$pin"
return $res
}
function show_text_dialog ()
{
title="$1"
text="$2"
$DIALOG --title "$title" --no-nl-expand --msgbox "$text" 0 0
return $?
}
function yesno ()
{
title="$1"
text="$2"
$DIALOG --title "$title" --no-nl-expand --yesno "$text" 0 0
return $?
}
function show_wait_dialog ()
{
show_text "$1" "$2"
return $?
}
function get_string ()
{
title="$1"
msg="$2"
default="$3"
string=`$DIALOG --title "$title" --inputbox "$msg" 0 0 "$default"`;
ret=$?
echo -e "$string"
return $ret
}
function show_form ()
{
title="$1"
msg="$2"
asks="$3"
default="$4"
echo -e "$asks" > asks
echo -e "$default" > defaults
END=`cat asks | wc -l`
for ((i=1;i<=END;i++)); do echo $i; done > nums
for ((i=1;i<=END;i++)); do echo 1; done > ones
for ((i=1;i<=END;i++)); do echo 2; done > twoes
for ((i=1;i<=END;i++)); do echo 30; done > lens
form=`paste asks nums ones defaults nums lens lens lens | tr '\n\t' '\0\0' | xargs -0 $DIALOG --title "$title" --form "$msg" 0 0 0`
if [[ -z "$form" ]]
then
return 255
fi
ret=$?
echo -e "$form"
return $ret
}
function save_file_dialog()
{
title="$1"
text="$2"
start_dir="$3"
file=`$DIALOG --title "$title" --fselect "$start_dir" 14 48`
res=$?
echo -e "$file"
return $res
}
function open_file_dialog()
{
title="$1"
text="$2"
start_dir="$3"
file=`$DIALOG --title "$title" --fselect "$start_dir" 14 48`
res=$?
echo -e "$file"
return $res
}
function dialog_manager_enabeled()
{
dialog --help > /dev/null
return $?
}