adding exec feature

This commit is contained in:
ville rantanen
2014-04-16 19:25:15 +03:00
parent 4aad97d4ee
commit e7d42d706d

View File

@@ -14,6 +14,37 @@ function display_self {
exit 1
}
function display_slide {
j=$(( $2 + 1 ))
echo -en "$CLS"
awk 'match($0,/^# /){
c++;
print c $0;
}
!/^# /{
print $0;
}
' "$1" | sed -n '/^'$2'# /,/^'$j'# /p' | grep -v "^$j# " | sed 's,^'$i'\(# .*\),'$H'\1'$Z',' | eval sed $REGEX
}
function slide_exec {
# find executables in the slide
j=$(( $2 + 1 ))
echo -en "$CLS"
while read line
do eval $line > /dev/null 2>&1 &
done < <(
awk 'match($0,/^# /){
c++;
print c $0;
}
!/^# /{
print $0;
}
' "$1" | sed -n '/^'$2'# /,/^'$j'# /p' | grep "^\$( " | sed -e 's,^\$( ,,' -e 's,)$,,' )
}
E='\x1b['
H="${E}1m"
Z="${E}0m"
@@ -44,6 +75,7 @@ for (( r=0; r<${#CONF_LINE[@]}; r++ ));
replace=$( eval echo ${!value} )
REGEX="$REGEX -e 's/\(${CONF_LINE[$r]}\)/"${replace}"/g'"
done
REGEX="$REGEX -e 's/^\$([^\$]\+)/\$(*)/g'"
#echo $REGEX
#exit
@@ -54,38 +86,31 @@ do
# print slide $i
NO_SLIDES=$( grep -ce "^# " "$1" )
COLS=$(( $( tput cols ) - 3 ))
j=$(( $i + 1 ))
echo -en "$CLS"
awk 'match($0,/^# /){
c++;
print c $0;
}
!/^# /{
print $0;
}
' "$1" | sed -n '/^'$i'# /,/^'$j'# /p' | grep -v "^$j# " | sed 's,^'$i'\(# .*\),'$H'\1'$Z',' | eval sed $REGEX
display_slide "$1" $i
# ask for user input
# 1 back, 2 forward, q exit, h help
# 1 back, 2 forward, q exit, m menu
echo -ne "${Z}${E}1;${COLS}H"
[ -z "$MENU" ] || {
echo -ne "${i}/${NO_SLIDES}"
echo -ne "${E}1B${E}3D1:▶"
echo -ne "${E}1B${E}3D2:◀"
echo -ne "${E}1B${E}3Dq:x"
echo -ne "${E}1B${E}3Dh:▲${E}4A"
echo -ne "${E}1B${E}3Dm:▲${E}4A"
}
read -s -N 1 cmd
# Escape inputed if arrow keys used
[ "$cmd" = "" ] && read -s -N 2 cmd
case "$cmd" in
2)
2|"[D")
i=$(( $i - 1 ))
[ $i -lt 1 ] && i=1
;;
1)
1|"[C"|"")
i=$(( $i + 1 ))
[ $i -gt $NO_SLIDES ] && i=$NO_SLIDES
;;
h)
m)
[ -z "$MENU" ] && {
MENU=1
} || {
@@ -96,6 +121,9 @@ do
echo -ne "${E}1E"
exit
;;
e)
slide_exec "$1" $i
;;
esac
done
@@ -116,7 +144,7 @@ exit
* Move to the next slide with key 1
* Move to the previous slide with key 2
* Exit with q or x
* Hide menu with h
* Hide menu with m
* The numbers on the right show the current
and number of slides in this presentation
@@ -165,7 +193,6 @@ Object Area Perimeter
Background colors: BGR BGG BGB BGC BGM BGY BGW
Reset colors with ${ Z}
# Hints: Presenting
* Use a terminal with large font, perhaps 80 columns on screen
@@ -173,6 +200,9 @@ Object Area Perimeter
┌──────┐
* Get creative with │Ascii!│
└┬────┬┘
* Run any command with pressing "e" on a slide with
syntax beginning a row: "$ ( command )"
$( xeyes )
# Hints: Other tools