all repos — shlide @ d6337342fb051091cee4a3e00c6726d437ecfd22

slide deck presentation tool written in pure bash

shlide (view raw)

 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
#!/usr/bin/env bash
# 
# Usage: shlide path/to/slides/
# Each slide is a textfile under path/to/slides

# Color definitions

BLK="\e[30m"
RED="\e[31m"
GRN="\e[32m"
YLW="\e[33m"
BLU="\e[34m"
PUR="\e[35m"
CYN="\e[36m"
RST="\e[0m"

lstrip() {
    # See: https://github.com/dylanaraps/pure-bash-bible#strip-pattern-from-start-of-string
    printf '%s\n' "${1##$2}"
}

get_term_size() {

    # POSIX alternative to 'checkwinsize'.
    read -r LINES COLUMNS < <(stty -F /dev/tty size)

}

# navigate() {
#     case "$1" in
#         "j") 
# }

display() {
    # 1 - slide contents
    # 2 - slide name

    slide_contents="$1"
    # slide_name="$(lstrip $2 "[0-9]-")"

    # Hides the cursor.
    printf '\e[?25l'

    # Clear the screen.
    printf '\e[2J'

    # Move the cursor to the center.
    get_term_size

    # Rough estimates for the true center.
    ((l=0))
    ((c=0))
    printf '\e[%s;%sH' "$l" "$c"

    while IFS= read -r line; do
        # Print the contents of the slide file, 
        # line by line.
        printf "%s" "$line"
        # Move down and back after each print.
        printf '\e[%sD\e[B' "${#line}"
    done <<< "$slide_contents"

    # Change slide on space.
    read -rsn1 input
    #navigate "$input"
}

main() {
    
    slides_dir="$1"

    for f in "$slides_dir"/[0-9]*.txt; do
        f_contents="$(<$f)"
        display "$f_contents" "$f"
    done
               
    # Return the cursor.
    printf '\e[?25h'

}

main "$@"