-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs
executable file
·188 lines (143 loc) · 3.08 KB
/
funcs
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#! /bin/bash
# The intention is for copy-pasting what you need out of this file, not really
# for it to be used as a library or include file
ESC="\0033["
OSC="\0033]"
BEL="\0007"
SEP=";"
ELLIPSIS="…"
gx=0
gy=0
mx=0
my=0
sx=0
sy=0
n=1
function gotoXY() {
x=$1; y=$2
echo -en "${ESC}$((y))${SEP}$((x))H"
}
# gotoXY 1 1; echo -n "1"
# gotoXY 1 2; echo -n "|"
# gotoXY 1 3; echo -n "|"
# gotoXY 2 2; echo -n "2"
# gotoXY 3 3; echo -n "3"
function moveXY() {
mx=$1; my=$2
if [[ $mx -lt 0 ]]; then
echo -en "${ESC}$((-mx))D"
elif [[ $mx -gt 0 ]]; then
echo -en "${ESC}$((mx))C"
fi
if [[ $my -lt 0 ]]; then
echo -en "${ESC}$((-my))A"
elif [[ $my -gt 0 ]]; then
echo -en "${ESC}$((my))B"
fi
}
# moveXY 0 1; echo -n "*"
# moveXY 0 1; echo -n "*"
# moveXY 0 1; echo -n "*"
# moveXY 1 0; echo -n "*"
# moveXY 1 0; echo -n "*"
# moveXY 1 0; echo -n "*"
function moveUp() {
n="${1:-1}"
echo -en "${ESC}${n}A"
}
#echo -n "Here"; moveUp 3; echo -n "Up 3"
function moveDown() {
n="${1:-1}"
echo -en "${ESC}${n}B"
}
function moveForward() {
n="${1:-1}"
echo -en "${ESC}${n}C"
}
function moveBackward() {
n="${1:-1}"
echo -en "${ESC}${n}D"
}
function gotoLeft() {
echo -en "${ESC}1G"
}
#echo -n "Hello"; gotoLeft; echo -n "h"
# moveUp; moveUp; echo -n "Boo"
# moveDown; moveDown; echo -n "Boo"
function savePosition() {
echo -en "${ESC}s"
}
function restorePosition() {
echo -en "${ESC}u"
}
# savePosition; gotoLeft; echo -n "Left"; restorePosition; echo "More"
function setXY() {
exec < /dev/tty
local _oldstty=$(stty -g)
stty raw -echo min 0
echo -en "\033[6n" > /dev/tty
IFS=';' read -r -d R -a pos
stty $_oldstty
sx=$((${pos[1]} - 1))
sy=$((${pos[0]:2}))
}
function nextLine() {
echo -en "${ESC}E"
}
function previousLine() {
echo -en "${ESC}F"
}
function hideCursor() {
echo -en "${ESC}?25l"
}
function showCursor() {
echo -en "${ESC}?25h"
}
function disableWordWrap() {
echo -ne "${ESC}[?7l"
}
function enableWordWrap() {
echo -ne "${ESC}[?7h"
}
# sleep 1; previousLine; sleep 1; previousLine;
# sleep 1; hideCursor; sleep 1; showCursor; echo -n "Back"
function eraseEndLine() {
echo -en "${ESC}K"
}
function eraseStartLine() {
echo -en "${ESC}1K"
}
function eraseLine() {
echo -en "${ESC}2K"
}
function eraseDown() {
echo -en "${ESC}J"
}
function eraseUp() {
echo -en "${ESC}1J"
}
function eraseScreen() {
echo -en "${ESC}2J"
}
function scrollUp() {
echo -en "${ESC}S"
}
function scrollDown() {
echo -en "${ESC}T"
}
function link() { # $1 url, $2 text
echo -en "${OSC}8${SEP}${SEP}$1${BEL}$2${OSC}8${SEP}${SEP}${BEL}"
}
# link https://www.google.com Google
function enterAlternateScreen() {
echo -en "${ESC}?1049h"
}
function exitAlternateScreen() {
echo -en "${ESC}?1049l"
}
# sleep 1; enterAlternateScreen; echo "Alternate screen!"; sleep 1; exitAlternateScreen;
# TODO:
# 2. update shui to use these functions (copy those needed in)
# 3. fix shui to not write lines longer than the width of terminal
savePosition; hideCursor; gotoXY 10000 10000; setXY; restorePosition; showCursor
echo "screen width: $sx, height: $sy"