-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserinterface.sh
131 lines (122 loc) · 3.31 KB
/
userinterface.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
#!/bin/bash
userinterface:question() {
local input="" text="sure?[y/N]:> " true="[yY]"
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[tT][eE][xX][tT]|-[tT][eE])
shift
if [[ -n "${1}" ]] ; then
local text="${1}"
shift
fi
;;
--[tT][rR][uU][eE]|-[tT][rR])
shift
if [[ -n "${1}" ]] ; then
local true="${1}"
shift
fi
;;
*)
shift
;;
esac
done
read -p "${text}" input
case "${input}" in
${true})
return 0
;;
*)
return 1
;;
esac
}
userinterface:spinner:line() {
local count="0" total="34" sleep="0.5" pstr="[=======================================================================]"
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[cC][oO][uU][nN][tT]|-[cC])
shift
if [[ -n "${1}" ]] ; then
local count="${1}"
shift
fi
;;
--[tT][oO][tT][aA][lL]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local total="${1}"
shift
fi
;;
--[sS][lL][eE][eE][pP]|-[sS])
shift
if [[ -n "${1}" ]] ; then
local sleep="${1}"
shift
fi
;;
*)
shift
;;
esac
done
while [ $count -lt $total ]; do
sleep "${sleep}" # this is work
count=$(( $count + 1 ))
pd=$(( $count * 73 / $total ))
printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr
done
}
userinterface:output() {
local text="sample output text from ${0##*/}:${FUNCNAME##*:}" TYPE="success"
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--[tT][eE][xX][tT]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local text="${1}"
shift
fi
;;
--[sS][uU][cC][cC][eE][sS][sS]|-[sS])
shift
local TYPE="success"
;;
--[eE][rR][rR][oO][rR]|-[eE])
shift
local TYPE="error"
;;
--[iI][nN][fF][oO]|-[iI])
shift
local TYPE="info"
;;
--[tT][yY][pP][eE]|-[tT])
shift
if [[ -n "${1}" ]] ; then
local TYPE="${1}"
shift
fi
;;
*)
shift
;;
esac
done
case "${TYPE}" in
success)
echo -e "\t${0##*/}: \033[0;32mSUCCESS\033[0m: ${text}\033[0m"
;;
error)
echo -e "\t${0##*/}: \033[0;31mERROR\033[0m: ${text}\033[0m"
return 1
;;
info)
echo -e "\t${0##*/}: \033[0;34mINFO\033[0m: ${text}\033[0m"
;;
*)
echo -e "\t${0##*/}: ${FUNCNAME##*:}: ${TYPE}: ${text}"
;;
esac
}