share
share copied to clipboard
slowcat, a utility to print files with delays
Add a slowcat
utility.
On basic files, slowcat
does the same as cat
. For instance:
-
slowcat file1 file2
prints the contents offile1
, thenfile2
, to stdout -
slowcat
orslowcat -
copies stdin to stdout
The behavior is modified if there are commands in the file, as follows.
Commands
All commands are lines beginning with "#
" (that is, a "#
" after a newline, or at the beginning of the file).
Comment
A line starting "#
" is a comment. The line is not printed to stdout.
Delay
A line of the form "#delay N
" sets the delay to N milliseconds. (Also emits a newline with zero delay.) Subsequent characters will be N milliseconds apart.
Pause
A line of the form "#pause N
" pauses for N milliseconds. (Also emits a newline with zero delay.)
Bugs & features
- In
delay
andpause
commands, allow fractions and units.10ms
and0.01s
mean10
. (Units are consistent with thesleep
command.) - Add a command-line flags to specify initial
delay
and initialpause
. - Implement reading from multiple files. (To be decided: what is the behavior if a command is split between files?)
- Add an
at
command that waits until a particular time. For example#at 00:01:00.5
waits until 60.5 seconds after the start of the script. - If a command line has a a "
#
" suffix, it should not output a newline.- Currently commands do not output a newline, but they should if their last character is not "
#
"
- Currently commands do not output a newline, but they should if their last character is not "
- Allow different delays for different character classes (e.g spaces and newlines).
- Randomized delays to simulate human typing.
- Set status code consistent with
cat
. - Add a
--help
command line option. - Add commands that output a "
#
", and "#
" followed by newline. Perhaps "##
<newline>" and "###
<newline>". - Add command that outputs a comment. Perhaps "
## a comment
" would output "# a comment
". - Support Windows line endings.
A rough version of this functionality is in 70cd8d9.
The utility is tools/play.sh
and is backed by scratch/src/main/java/net/hydromatic/scratch/Play.java
.
In case you're wondering. I wrote this script so that I could automate creation of recordings for asciinema.
A few utilities (e.g. Morel and SQLLine, both based on JLine3) behave differently if their input is stdin rather than a terminal. I was able to solve this by running them via ssh -tt
, and piping stdout of play.sh
into the stdin of ssh
. The -tt
flag forces ssh
to allocate a pseudo-terminal.