| 1 |
#!/usr/bin/env tclsh |
| 2 |
# |
| 3 |
# PLAYDEMO, play demos recorded with asciinema |
| 4 |
# Copyright (C) 2019-2021 Xavier Delaruelle |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
########################################################################## |
| 20 |
|
| 21 |
set demoparentpath [file normalize [file dirname $argv0]/../doc/demo] |
| 22 |
set usage "Usage: $argv0 demo \[rep\] \[speed\] |
| 23 |
Play designated demo rep times at given speed" |
| 24 |
|
| 25 |
# parse command-line arguments |
| 26 |
lassign $argv demoname demorep demospeed |
| 27 |
if {$demoname eq "-h" || $demoname eq "--help"} { |
| 28 |
puts stderr $usage |
| 29 |
exit 0 |
| 30 |
} elseif {[llength $argv] > 3} { |
| 31 |
puts stderr $usage |
| 32 |
exit 1 |
| 33 |
} |
| 34 |
|
| 35 |
# verify args |
| 36 |
if {$demorep eq {}} { |
| 37 |
set demorep 1 |
| 38 |
} elseif {![string is integer -strict $demorep]} { |
| 39 |
puts stderr $usage |
| 40 |
exit 1 |
| 41 |
} |
| 42 |
if {$demospeed eq {}} { |
| 43 |
set demospeed 1 |
| 44 |
} elseif {![string is integer -strict $demospeed]} { |
| 45 |
puts stderr $usage |
| 46 |
exit 1 |
| 47 |
} |
| 48 |
|
| 49 |
# check demo exists |
| 50 |
set demopath $demoparentpath/$demoname |
| 51 |
if {![file isdirectory $demopath] || ![file readable $demopath]} { |
| 52 |
puts stderr "ERROR: $demoname does not exist or is not readable" |
| 53 |
exit 1 |
| 54 |
} |
| 55 |
|
| 56 |
# verify asciinema availability |
| 57 |
set asciinemapath [lindex [auto_execok asciinema] 0] |
| 58 |
if {$asciinemapath eq {}} { |
| 59 |
puts stderr "ERROR: command 'asciinema' cannot be found" |
| 60 |
exit 1 |
| 61 |
} |
| 62 |
|
| 63 |
# repeat demo play |
| 64 |
for {set i 0} {$i < $demorep} {incr i} { |
| 65 |
# play each file of the demo |
| 66 |
foreach demofile [lsort [glob $demopath/*.cast]] { |
| 67 |
exec $asciinemapath play -s $demospeed $demofile >@stdout 2>@stderr |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent syntax=tcl: |