-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs.sh
More file actions
executable file
·63 lines (53 loc) · 1.17 KB
/
funcs.sh
File metadata and controls
executable file
·63 lines (53 loc) · 1.17 KB
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
#/usr/local/bin/bash
# usage: explace <place_parameter> <window width> <text_length>
function explace {
case "$1" in
"left") echo 2;;
"center") echo $(($(($2/2))-$(($3/2)) ));;
"right") echo $(($2 - 2 - $3));; # -2 is for box line
esac
}
# usage: box <start_y> <width> <height> <string place>
function box {
local start_y=$1
local width=$2
local height=$3
local place=$4
local window=( "$(tput lines)" "$(tput cols)")
if [ "$5" = "-t" ]
then
while read line
do
text=(${text} "$line")
done
fi
local start_x=$(($(explace $place ${window[1]} $width)))
# write top "+------+"
tput cup $start_y $start_x
echo -n "+"
for num in $(seq $width)
do
echo -ne "-"
done
echo -ne "+\n"
# write mid "| |"
EoL=$(($start_x + $width + 1))
for i in $(seq $height)
do
tput cup $(($start_y+$i)) $start_x
echo -ne "| ${text[$(($i-1))]}"
tput cup $(($start_y + $i)) $EoL
echo -ne "|\n"
done
# write bottom "+-----------+"
tput cup $(($start_y + $height +1)) $start_x
echo -ne "+"
for num in $(seq $width)
do
echo -ne "-"
done
echo -ne "+\n"
}
case $1 in
"box") shift; box $@;;
esac