Skip to content

Commit 8eb4421

Browse files
committed
feat: Finalice interfaces and implement tput override
1 parent c5b825c commit 8eb4421

File tree

4 files changed

+206
-66
lines changed

4 files changed

+206
-66
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# bash-tty
22

3-
`tput` is slow as a dog due to subshell and exec overhead. Use functions like `tty.clear_screen` instead
3+
`tput` is slow as a dog due to subshell and exec overhead. Use functions like `term.clear_screen` instead
44

55
## Installation
66

77
Use [Basalt](https://github.com/hyperupcall/basalt), a Bash package manager, to add this project as a dependency
88

99
```sh
10-
basalt add 'hyperupcall/bash-tty'
10+
basalt add hyperupcall/bash-tty
1111
```
1212

13+
## Usage
14+
15+
- `BASH_TTY_FORCE_TPUT`
16+
1317
## Roadmap
1418

1519
- Add layer that accepts same strings are `tput`

pkg/src/public/bash-tty.sh renamed to pkg/src/public/bash-term.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Cursor #
55
# -------------------------------------------------------- #
66

7-
tty.cursor_to() {
7+
term.cursor_to() {
88
unset -v REPLY
99
local row="${1:-0}"
1010
local column="${2:-0}"
@@ -13,93 +13,93 @@ tty.cursor_to() {
1313
printf -v REPLY '\033[%s;%sH' "$row" "$column"
1414
}
1515

16-
tty.cursor_up() {
16+
term.cursor_up() {
1717
unset -v REPLY
1818
local count="${1:-1}"
1919

2020
printf -v REPLY '\033[%sA' "$count"
2121
}
2222

23-
tty.cursor_down() {
23+
term.cursor_down() {
2424
unset -v REPLY
2525
local count="${1:-1}"
2626

2727
printf -v REPLY '\033[%sB' "$count"
2828
}
2929

30-
tty.cursor_forward() {
30+
term.cursor_forward() {
3131
unset -v REPLY
3232
local count="${1:-1}"
3333

3434
printf -v REPLY '\033[%sC' "$count"
3535
}
3636

37-
tty.cursor_backward() {
37+
term.cursor_backward() {
3838
unset -v REPLY
3939
local count="${1:-1}"
4040

4141
printf -v REPLY '\033[%sD' "$count"
4242
}
4343

44-
tty.cursor_line_next() {
44+
term.cursor_line_next() {
4545
unset -v REPLY
4646
local count="${1:-1}"
4747

4848
printf -v REPLY '\033[%sE' "$count"
4949
}
5050

51-
tty.cursor_line_prev() {
51+
term.cursor_line_prev() {
5252
unset -v REPLY
5353
local count="${1:-1}"
5454

5555
printf -v REPLY '\033[%sF' "$count"
5656
}
5757

5858
# TODO: name, default?
59-
tty.cursor_tocolumn() {
59+
term.cursor_tocolumn() {
6060
unset -v REPLY
6161
local count="${1:-1}"
6262

6363
printf -v REPLY '\033[%sG' "$count"
6464
}
6565

6666
# @noargs
67-
tty.cursor_savepos() {
67+
term.cursor_savepos() {
6868
unset -v REPLY
6969

7070
REPLY=$'\e[s'
7171
}
7272

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

7777
REPLY=$'\e[u'
7878
}
7979

8080
# @noargs
81-
tty.cursor_save() {
81+
term.cursor_save() {
8282
unset -v REPLY
8383

8484
REPLY=$'\e[7'
8585
}
8686

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

9191
REPLY=$'\e[8'
9292
}
9393

9494
# @noargs
95-
tty.cursor_hide() {
95+
term.cursor_hide() {
9696
unset -v REPLY
9797

9898
REPLY=$'\e[?25l'
9999
}
100100

101101
# @noargs
102-
tty.cursor_show() {
102+
term.cursor_show() {
103103
unset -v REPLY
104104

105105
REPLY=$'\e[?25h'
@@ -111,14 +111,14 @@ tty.cursor_show() {
111111
# -------------------------------------------------------- #
112112

113113
# @noargs
114-
tty.scroll_down() {
114+
term.scroll_down() {
115115
unset -v REPLY
116116

117117
REPLY=$'\e[D'
118118
}
119119

120120
# @noargs
121-
tty.scroll_up() {
121+
term.scroll_up() {
122122
unset -v REPLY
123123

124124
REPLY=$'\e[M'
@@ -130,21 +130,21 @@ tty.scroll_up() {
130130
# -------------------------------------------------------- #
131131

132132
# @noargs
133-
tty.tab_set() {
133+
term.tab_set() {
134134
unset -v REPLY
135135

136136
REPLY=$'\e[H'
137137
}
138138

139139
# @noargs
140-
tty.tab_clear() {
140+
term.tab_clear() {
141141
unset -v REPLY
142142

143143
REPLY=$'\e[g'
144144
}
145145

146146
# @noargs
147-
tty.tab_clearall() {
147+
term.tab_clearall() {
148148
unset -v REPLY
149149

150150
REPLY=$'\e[3g'
@@ -156,51 +156,51 @@ tty.tab_clearall() {
156156
# -------------------------------------------------------- #
157157

158158
# @noargs
159-
tty.erase_line_end() {
159+
term.erase_line_end() {
160160
unset -v REPLY
161161

162162
# Same as '\e[0K'
163163
REPLY=$'\e[K'
164164
}
165165

166166
# @noargs
167-
tty.erase_line_start() {
167+
term.erase_line_start() {
168168
unset -v REPLY
169169

170170
REPLY=$'\e[1K'
171171
}
172172

173173
# @noargs
174-
tty.erase_line() {
174+
term.erase_line() {
175175
unset -v REPLY
176176

177177
REPLY=$'\e[2K'
178178
}
179179

180180
# @noargs
181-
tty.erase_screen_end() {
181+
term.erase_screen_end() {
182182
unset -v REPLY
183183

184184
# Same as '\e[0J'
185185
REPLY=$'\e[J'
186186
}
187187

188188
# @noargs
189-
tty.erase_screen_start() {
189+
term.erase_screen_start() {
190190
unset -v REPLY
191191

192192
REPLY=$'\e[1J'
193193
}
194194

195195
# @noargs
196-
tty.erase_screen() {
196+
term.erase_screen() {
197197
unset -v REPLY
198198

199199
REPLY=$'\e[2J'
200200
}
201201

202202
# @noargs
203-
tty.erase_saved_lines() {
203+
term.erase_saved_lines() {
204204
unset -v REPLY
205205

206206
REPLY=$'\e[3J'
@@ -211,13 +211,13 @@ tty.erase_saved_lines() {
211211
# Miscellaneous #
212212
# -------------------------------------------------------- #
213213

214-
tty.beep() {
214+
term.beep() {
215215
unset -v REPLY
216216

217217
REPLY=$'\a'
218218
}
219219

220-
tty.hyperlink() {
220+
term.hyperlink() {
221221
unset -v REPLY
222222
local text="$1"
223223
local url="$2"

0 commit comments

Comments
 (0)