share icon indicating copy to clipboard operation
share copied to clipboard

slowcat, a utility to print files with delays

Open julianhyde opened this issue 3 years ago • 2 comments

Add a slowcat utility.

On basic files, slowcat does the same as cat. For instance:

  • slowcat file1 file2 prints the contents of file1, then file2, to stdout
  • slowcat or slowcat - 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 and pause commands, allow fractions and units. 10ms and 0.01s mean 10. (Units are consistent with the sleep command.)
  • Add a command-line flags to specify initial delay and initial pause.
  • 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 "#"
  • 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.

julianhyde avatar Sep 13 '21 19:09 julianhyde

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.

julianhyde avatar Sep 13 '21 19:09 julianhyde

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.

julianhyde avatar Sep 13 '21 19:09 julianhyde