-
Notifications
You must be signed in to change notification settings - Fork 0
/
present.sh
executable file
·95 lines (79 loc) · 1.93 KB
/
present.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
function trap_winch() {
LINES="$(tput lines)"
COLUMNS="$(tput cols)"
redraw
}
function discover_slides() {
local slidefile="$1"
SLIDES=()
for slide_func in $(compgen -A "function" "slide_" ); do
read func line file <<< $(shopt -s extdebug; declare -F "$slide_func")
if [[ "$file" == "$slidefile" ]]; then
SLIDES["$line"]="$func"
fi
done
SLIDES=("${SLIDES[@]}")
}
function next_slide() {
if (( current_slide_number + 1 < ${#SLIDES[@]} )); then
(( current_slide_number++ ))
fi
redraw
}
function prev_slide() {
if (( current_slide_number > 0 )); then
(( current_slide_number-- ))
fi
redraw
}
function last_slide() {
current_slide_number="$((${#SLIDES[@]}-1))"
redraw
}
function first_slide() {
current_slide_number=0
redraw
}
function redraw() {
slideoutput="$("${SLIDES[$current_slide_number]}")"
clear
echo "$slideoutput" | pad_on_bottom "$LINES"
echo -n $'\e[?25l'
echo -n "$(black "$((current_slide_number+1))/${#SLIDES[@]}" | bold | pad_on_left "$COLUMNS")"
}
function check_input() {
input="$1"
case "$input" in
' ') next_slide;;
$'\e[6~'|$'\e[C') next_slide;;
$'\e[5~') prev_slide;;
$'\e[B') last_slide;;
$'\e[A') first_slide;;
$'\e[') return 1;;
$'\e[6') return 1;;
$'\e[5') return 1;;
$'\e') return 1;;
q|Q) exit;;
esac
}
function present() (
trap trap_winch WINCH
slidefile="$1"
source text_manipulations.sh
source "$slidefile"
discover_slides "$slidefile"
current_slide_number=0
trap_winch
input_buffer=""
while IFS='' read -sn1 key; do
input_buffer="${input_buffer}${key}"
if check_input "${input_buffer}"; then
input_buffer=''
fi
done
)
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
# not being sourced.
present "$@"
fi