-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor.sh
More file actions
54 lines (46 loc) · 1.93 KB
/
Copy pathcursor.sh
File metadata and controls
54 lines (46 loc) · 1.93 KB
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
#!/bin/sh
# Move the cursor $1 up
cursor_up() { printf '[%dA' "$1" >&2; }
# Move the cursor $1 down
cursor_down() { printf '[%dB' "$1" >&2; }
# Move the cursor $1 right
cursor_right() { printf '[%dC' "$1" >&2; }
# Move the cursor $1 left
cursor_left() { printf '[%dD' "$1" >&2; }
# Move the cursor tothe start of the line $1 lines down
cursor_line_down() { printf '[%dE' "$1" >&2; }
# Move the cursor tothe start of the line $1 lines up
cursor_line_up() { printf '[%dF' "$1" >&2; }
# Move the cursor to column $1
cursor_column() { printf '[%dG' "$1" >&2; }
# Move the cursor to row $1 column $2
cursor_position() { printf '[%d;%dH' "$1" "$2" >&2; }
# If $1 is 0 clear from cursor to the end of the screen, if $1 is 1 clear from cursor to the beginning of the screen, if $1 is 2 clear entire screen, if $1 is 3 clear entire string and delete scrollback buffer
erase_display() { printf '[%dJ' "$1" >&2; }
# If $1 is 0 clear from cursor to the end of the line, if $1 is 1 clear from cursor to the begining of the line, if $1 is 2 clear entire line
erase_line() { printf '[%dK' "$1" >&2; }
# Scroll $1 up
scroll_up() { printf '[%dS' "$1" >&2; }
# Scroll $1 down
scroll_down() { printf '[%dT' "$1" >&2; }
# Hides the cursor
cursor_hide() { printf '[?25l' >&2; }
# Shows the cursor
cursor_show() { printf '[?25h' >&2; }
# Saves the cursor position
cursor_save() { printf '[s' >&2; }
# Restores the cursor position
cursor_load() { printf '[u' >&2; }
cursor_get_position() {
oldstty=$(stty -g)
stty raw -echo min 0 time 1
printf '[6n' >&2;
IFS=';' read -r row col
stty "$oldstty"
printf '%d %d' "${row#*[}" "${col%R}"
}
cursor_get_row() { cursor_get_position | cut -d" " -f1; }
cursor_get_col() { cursor_get_position | cut -d" " -f2; }
terminal_get_size() { stty size; }
terminal_get_width() { terminal_get_size | cut -d" " -f1; }
terminal_get_height() { terminal_get_size | cut -d" " -f2; }