Skip to content

Instantly share code, notes, and snippets.

@cmatheson
Created January 30, 2014 19:33
Show Gist options
  • Save cmatheson/8716981 to your computer and use it in GitHub Desktop.
Save cmatheson/8716981 to your computer and use it in GitHub Desktop.
command-line slide viewer
#!/usr/bin/env ruby
require 'io/console'
msg = ARGV.shift or fail "no message text given"
rows, cols = IO.console.winsize
msg_lines = msg.lines.count
vert_padding = "\n" * ((rows - msg_lines) / 2)
extra_padding = "\n" unless ((rows - msg_lines) % 2).zero?
extra_padding ||= ""
msg_line = lambda { |l|
padding = " " * ((cols - l.chomp.size) / 2)
padding << l.chomp
}
print vert_padding +
msg.lines.map { |l| msg_line.(l) }.join("\n") +
vert_padding +
extra_padding
if IO.console.getch == "q"
exit 1
end
#!/bin/bash
# usage: slideshow.sh directory-with-slides
slide_dir=$1
slides=
i=0
for slide in $slide_dir/*; do
[ -d $slide ] && continue
slides[$i]=$slide
(( i++ ))
done
i=0
while [ -n "${slides[$i]}" ]; do
if [ -x ${slides[$i]} ]; then
${slides[$i]}
else
./present.rb "$(cat ${slides[$i]})"
if [ $? -ne 0 ]; then
(( i-- ))
clear
continue
fi
fi
(( i++ ))
clear
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment