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