+21
-5
shlide
+21
-5
shlide
···
19
printf '%s\n' "${1##$2}"
20
}
21
22
-
get_term_size() {
23
24
# POSIX alternative to 'checkwinsize'.
25
read -r LINES COLUMNS < <(stty -F /dev/tty size)
26
···
45
printf '\e[2J'
46
47
# Move the cursor to the center.
48
-
get_term_size
49
50
# Rough estimates for the true center.
51
-
((l=0))
52
-
((c=0))
53
printf '\e[%s;%sH' "$l" "$c"
54
55
while IFS= read -r line; do
···
73
f_contents="$(<$f)"
74
display "$f_contents" "$f"
75
done
76
-
77
# Return the cursor.
78
printf '\e[?25h'
79
···
19
printf '%s\n' "${1##$2}"
20
}
21
22
+
lines() {
23
+
mapfile -tn 0 lines < "$1"
24
+
printf '%s\n' "${#lines[@]}"
25
+
}
26
+
27
+
longest_line() {
28
+
max=0 IFS=
29
+
while read -r line; do
30
+
if [ "${#line}" -gt "$max" ]; then max="${#line}"; fi
31
+
done < "$1"
32
+
printf '%s\n' "$max"
33
+
}
34
35
+
get_term_size() {
36
# POSIX alternative to 'checkwinsize'.
37
read -r LINES COLUMNS < <(stty -F /dev/tty size)
38
···
57
printf '\e[2J'
58
59
# Move the cursor to the center.
60
+
read -r LINES COLUMNS < <(stty -F /dev/tty size)
61
+
height=$(lines "$2")
62
+
width=$(longest_line "$2")
63
64
+
echo "$height $width" >> log.txt
65
# Rough estimates for the true center.
66
+
((l=$LINES/2 - $height/2))
67
+
((c=$COLUMNS/2 - $width/2))
68
+
69
printf '\e[%s;%sH' "$l" "$c"
70
71
while IFS= read -r line; do
···
89
f_contents="$(<$f)"
90
display "$f_contents" "$f"
91
done
92
+
93
# Return the cursor.
94
printf '\e[?25h'
95