-
Notifications
You must be signed in to change notification settings - Fork 0
/
libdraw.sh
70 lines (57 loc) · 1.18 KB
/
libdraw.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
# libdraw
#
# copyright (c) 2018 Cj-bc
#
# @(#) ver.0.2.4
# draw <picture> at <x>, <y>
# @param <int x> <int y> <string picture>
Draw::drawAt() {
pos_x=$1
pos_y=$2
file=$3
declare -i i=1
tput civis # hide cursor
tput cup $pos_y $pos_x
while IFS= read -r line; do
echo -n "$line"
tput cup $(( $pos_y + $i)) $pos_x
i+=1
done < $file
tput cnorm # appear cursor
}
# Erase whole area <x1> <y1> to <x2> <y>
# @param <int x> <int y> <int width> <int height>
Draw::erase() {
local -i pos_x
local -i pos_y
local -i width
local -i height
pos_x=$1
pos_y=$2
width=$3
height=$4
tput cup $pos_y $pos_x
for i in $(seq 0 $height); do
seq -s ' ' $width | tr -d "[:digit:]" # echo ' ' for $width length
done
}
# Erase whole area of the <picture> from <x> <y>
# @param <int x> <int y> <string file>
Draw::erasePicture(){
local -i pos_x=$1
local -i pos_y=$2
local file=$3
tput civis
tput cup $pos_y $pos_x
local -i i=1
while IFS= read -r line; do
seq -s ' ' $(echo -En "$line" | wc -m) | tr -d "[:digit:]"
tput cup $(( $pos_y + $i)) $pos_x
i+=1
done < $file
tput cnorm
}
# clear whole screen
Draw::clearScreen() {
tput clear
}