-
Notifications
You must be signed in to change notification settings - Fork 4
/
ansi.sh
82 lines (69 loc) · 1.19 KB
/
ansi.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
color() {
printf '\e[%dm' "$1"
}
bold() {
color 1
}
unbold() {
color 22
}
sttysize() {
read h w < <( stty size 2>/dev/null )
el=$?
if (( el == 0 )); then
SCREEN_WIDTH=${w}
SCREEN_HEIGHT=${h}
echo -en "\e[1;1H"
echo -en "\e[7m"
PPL_STATUS_LINE=""
for (( i=0; i<SCREEN_WIDTH; i++ )); do
PPL_STATUS_LINE+=" "
done
echo -n "${PPL_STATUS_LINE}"
echo -en "\e[27m"
echo -ne "\e[2;$(( SCREEN_HEIGHT ))r"
echo -en "\e[2;1H"
fi
return $el
}
drawstatusline() {
echo -en "\e7"
echo -en '\e[1;1H'
echo -en "\e[7m"
echo -en "\r"
echo -n "${PPL_STATUS_LINE}"
echo -en "\e[27m"
echo -en "\e8"
}
statusmake() {
local right
printf -v right "%${SCREEN_WIDTH}s" "$PPL_STATUS_RIGHT"
local leftlen
leftlen="${#PPL_STATUS_LEFT}"
PPL_STATUS_LINE="${PPL_STATUS_LEFT}${right:$leftlen}"
drawstatusline
}
statusleft() {
echo "statusleft $@" > /tmp/scroller2
return
PPL_STATUS_LEFT="${1}"
statusmake
}
scrollinit() {
echo "scrollinit" "$@" > /tmp/scroller2
}
statusmiddle() {
PPL_STATUS_MIDDLE="{$@}"
}
statusright() {
echo "statusright $PPL_STATUS_MIDDLE $@" > /tmp/scroller2
return
PPL_STATUS_RIGHT="${1}"
statusmake
}
ansion() {
sttysize
}
ansioff() {
echo -ne "\e[r\ec"
}