animate: Add -c option for variable-width frames
Not all scripts produce fixed-width frames. Variable-width frames leave behind artifacts caused by characters from the previous frame not being overwritten. * regex/animate (usage): Document new `-c' flag. (main): Handle new `-c' flag. [refresh]: New variable. * regex/base10-mul.sed: Remove extra whitespace used for frame clearing for animate script (just use `-c' now).master
parent
2dd5b590f9
commit
3f5c397e83
|
@ -23,13 +23,19 @@ set -euo pipefail
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $0 script frame [speed]
|
Usage: $0 [-c] script frame [speed]
|
||||||
Recursively render FRAME using SCRIPT
|
Recursively render FRAME using SCRIPT
|
||||||
|
|
||||||
The current frame is stored in the file \`last-frame' in the working
|
The current frame is stored in the file \`last-frame' in the working
|
||||||
directory. It may be used to continue the animation after quitting,
|
directory. It may be used to continue the animation after quitting,
|
||||||
or save the state of the system.
|
or save the state of the system.
|
||||||
|
|
||||||
|
To prevent flickering, each frame is rendered atop of the previous without
|
||||||
|
clearing the screen (your terminal must support this). This is desirable
|
||||||
|
for fixed-width frames, but not for scripts with variable-width output,
|
||||||
|
since that will leave behind artifacts. Provide the \`-c' flag to clear the
|
||||||
|
screen before rendering each frame.
|
||||||
|
|
||||||
SPEED should be a value recognized by the \`sleep' command. It defaults
|
SPEED should be a value recognized by the \`sleep' command. It defaults
|
||||||
to 0.25 to give some level of appreciation for each frame while still
|
to 0.25 to give some level of appreciation for each frame while still
|
||||||
looking animated. It looks fairly smooth at 0.05 but can go much faster on
|
looking animated. It looks fairly smooth at 0.05 but can go much faster on
|
||||||
|
@ -37,6 +43,7 @@ modern systems.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
$0 fall.sed fall/frame-lalaloop
|
$0 fall.sed fall/frame-lalaloop
|
||||||
|
$0 -c base10-mul.sed <( echo 010 005 ) 0.1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
exit 64 # EX_USAGE
|
exit 64 # EX_USAGE
|
||||||
|
@ -56,6 +63,15 @@ render()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
# Do not clear the screen on each frame by default (we'll be using tput
|
||||||
|
# to avoid flickering; see `render'). Certain scripts do not produce
|
||||||
|
# fixed-width frames, and so we must clear to avoid artifacts.
|
||||||
|
declare refresh=true
|
||||||
|
test "${1:-}" == -c && {
|
||||||
|
refresh=clear
|
||||||
|
shift
|
||||||
|
}
|
||||||
|
|
||||||
test $# -ge 2 -a $# -le 3 || usage
|
test $# -ge 2 -a $# -le 3 || usage
|
||||||
|
|
||||||
local -r script=${1?Missing script}
|
local -r script=${1?Missing script}
|
||||||
|
@ -67,7 +83,10 @@ main()
|
||||||
clear
|
clear
|
||||||
render "$speed"
|
render "$speed"
|
||||||
|
|
||||||
while sed -f "$script" -i last-frame; do render "$speed"; done
|
while sed -f "$script" -i last-frame; do
|
||||||
|
$refresh
|
||||||
|
render "$speed";
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
@ -94,10 +94,8 @@ s/^\(...\) 000/000 001/
|
||||||
# register two is `001'), then we are done! If that's the case, clean up
|
# register two is `001'), then we are done! If that's the case, clean up
|
||||||
# our output to display only the final result. The script will
|
# our output to display only the final result. The script will
|
||||||
# automatically exit with a non-zero status the next iteration because of
|
# automatically exit with a non-zero status the next iteration because of
|
||||||
# the guard at the top of this script. The trailing spaces ensure that
|
# the guard at the top of this script.
|
||||||
# leftover output from previous iterations is erased in the animation
|
s/^\(...\) 001.*/\1/
|
||||||
# script.
|
|
||||||
s/^\(...\) 001.*/\1 /
|
|
||||||
/^... \+$/b
|
/^... \+$/b
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue