Skip to content

Commit 617ca23

Browse files
committed
feat: Add screen save/restore, remove env checking
As per the release notes of `v0.2.0`, the environment variable check has been removed. Extra functions have been implemented and variables with 'unsave' have been renamed to 'restore'
1 parent 341b529 commit 617ca23

File tree

2 files changed

+43
-119
lines changed

2 files changed

+43
-119
lines changed

pkg/src/public/bash-term.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ term.cursor_savepos() {
7171
}
7272

7373
# @noargs
74-
term.cursor_unsavepos() {
74+
term.cursor_restorepos() {
7575
unset -v REPLY
7676

7777
REPLY=$'\e[u'
@@ -85,7 +85,7 @@ term.cursor_save() {
8585
}
8686

8787
# @noargs
88-
term.cursor_unsave() {
88+
term.cursor_restore() {
8989
unset -v REPLY
9090

9191
REPLY=$'\e[8'
@@ -200,13 +200,29 @@ term.erase_screen() {
200200
}
201201

202202
# @noargs
203-
term.erase_saved_lines() {
203+
term.erase_saved_lines() { # TODO: better name?
204204
unset -v REPLY
205205

206206
REPLY=$'\e[3J'
207207
}
208208

209209

210+
# -------------------------------------------------------- #
211+
# Screen #
212+
# -------------------------------------------------------- #
213+
term.screen_save() {
214+
unset -v REPLY
215+
216+
REPLY=$'\e[?1049h'
217+
}
218+
219+
term.screen_restore() {
220+
unset -v REPLY
221+
222+
REPLY=$'\e[?1049l'
223+
}
224+
225+
210226
# -------------------------------------------------------- #
211227
# Miscellaneous #
212228
# -------------------------------------------------------- #

pkg/src/public/bash-tput.sh

Lines changed: 24 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,28 @@ btput() {
1010
case $1 in
1111
# controlling cursor
1212
sc)
13-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
14-
tput sc
15-
else
16-
:
17-
fi
13+
term.cursor_savepos
1814
;;
1915
rc)
20-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
21-
tput rc
22-
else
23-
:
24-
fi
16+
term.cursor_unsavepos
2517
;;
2618
home)
27-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
28-
tput home
29-
else
30-
:
31-
fi
19+
tput home
3220
;;
3321
cup)
34-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
35-
tput cup
36-
else
37-
:
38-
fi
22+
term.cursor_to "$1" "$2"
3923
;;
4024
cud1)
41-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
42-
tput cud1
43-
else
44-
:
45-
fi
25+
tput cud1
4626
;;
4727
cuu1)
48-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
49-
tput cuu1
50-
else
51-
:
52-
fi
28+
tput cuu1
5329
;;
5430
civis)
55-
tput civis
31+
term.cursor_hide
5632
;;
5733
cnorm)
58-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
59-
tput cnorm
60-
else
61-
:
62-
fi
34+
term.cursor_show
6335
;;
6436

6537
# terminal attributes
@@ -70,67 +42,31 @@ btput() {
7042

7143
# text effects
7244
bold)
73-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
74-
tput bold
75-
else
76-
:
77-
fi
45+
tput bold
7846
;;
7947
smul)
80-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
81-
tput smul
82-
else
83-
:
84-
fi
48+
tput smul
8549
;;
8650
rmul)
87-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
88-
tput rmul
89-
else
90-
:
91-
fi
51+
tput rmul
9252
;;
9353
rev)
94-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
95-
tput rev
96-
else
97-
:
98-
fi
54+
tput revi
9955
;;
10056
blink)
101-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
102-
btput blink
103-
else
104-
:
105-
fi
57+
btput blink
10658
;;
10759
invis)
108-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
109-
itput invis
110-
else
111-
:
112-
fi
60+
itput invis
11361
;;
11462
smso)
115-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
116-
tput smso
117-
else
118-
:
119-
fi
63+
tput smso
12064
;;
12165
rmso)
122-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
123-
tput rmso
124-
else
125-
:
126-
fi
66+
tput rmso
12767
;;
12868
sgr0)
129-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
130-
tput sgr0
131-
else
132-
:
133-
fi
69+
tput sgr0
13470
;;
13571
setaf)
13672
case $2 in
@@ -145,55 +81,27 @@ btput() {
14581
esac
14682
;;
14783
dim)
148-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
149-
tput dim
150-
else
151-
:
152-
fi
84+
tput dim
15385
;;
15486

15587
# clearing screen
15688
smcup)
157-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
158-
tput smcup
159-
else
160-
:
161-
fi
89+
term.screen_save
16290
;;
16391
rmcup)
164-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
165-
tput rmcup
166-
else
167-
:
168-
fi
92+
term.screen_restore
16993
;;
17094
el)
171-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
172-
tput el
173-
else
174-
term.erase_line_end
175-
fi
95+
term.erase_line_end
17696
;;
17797
el1)
178-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
179-
tput el1
180-
else
181-
term.erase_line_start
182-
fi
98+
term.erase_line_start
18399
;;
184100
el2)
185-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
186-
tput el2
187-
else
188-
term.erase_line
189-
fi
101+
term.erase_line
190102
;;
191103
clear)
192-
if [[ -v BASH_TTY_FORCE_TPUT ]]; then
193-
tput clear
194-
else
195-
:
196-
fi
104+
tput clear
197105
;;
198106
*)
199107
return

0 commit comments

Comments
 (0)