Git Product home page Git Product logo

velocityper's Introduction

velocityper

velocityper is a command-line utility that allows data to be "stuffed" into the buffer of a terminal, as if entered by the keyboard.

Imagine you're running a demo and recording your terminal session for an online tutorial. You want to talk and sound cool, but how can you be cool when you're entering insanely precise command strings? Worse, when you make mistakes and have to self-correct while debugging your problems, completely losing cool points by the bucket. Sure, you could just "cut-n-paste" snippets, or use a clipboard manager, a "cut-n-paste" tool with multiple entries.

But you really just want something simpler, something that will enter the keystrokes for you, making it look natural but without typos. And you want to be able to switch easily between canned keystrokes and real interactive stuff, say when someone asks a question. You don't want to be completely locked into a fixed script.

Enter velocityper, a tool that does all this and makes your demo smooth and maximally slick.

  • velocityper includes parameters that introduce delays to make keystrokes

appear at a natural cadence, mimicking human typing speeds.

  • velocityper can pause during the demo, waiting until you hit RETURN (in

response to a prompt in a different terminal) to tell it to proceed.

  • velocityper can emit control characters via escape sequences in the text, including "n", "r", and "t", as well as "xYZ" for arbitrary hex values.
  • velocityper allows content in either provided on the command line, or via data file. Files are typically better for longer or more complex data, but command line allows velocityper to be incorporated into shell scripts that can react to current situations.
  • velocityper allows command-line options in data files, so you can control delay times, invoke pauses, and other options.

Units

Options that accept time values default to using milliseconds as the units, but support the following units as suffixes:

Short   Long Form     Nanoseconds
ns      nanoseconds               1
us      microseconds          1,000
ms      milliseconds      1,000,000
s       seconds       1,000,000,000

Leading strings can be used for brevity; for example "nano" can be used to nanoseconds.

Options

velocityper supports a variety of command-line option for tuning its behavior, and these options can appear in input files. Several of them are better suited for such files, but are also supported on the command line for con- sistency. See the "FILE FORMAT" section below for details.

The following options are supported:

-b | --bump
      Introduce a random addition to the intra-charater wait value given
      with the --wait option, giving the text a means of appearing more
      natural and less automated.  For example, using "--wait 40 --bump
      60" means a delay of 40ms plus a bump of 0-60ms, for  complete range
      of 40-100ms.

-C <terminal> | --confirm <terminal>
      Provides a managing terminal used for prompting for confirmations.

-f <filename> | --file <filename>
      Use the given file as content.  See the "FILE FORMAT" section below.

-F | --force
      Ignore any confirmations requested by the --pause-confirm option.

-l <delay> | --line <delay>
      Introduce a delay after each line of data.

-n | --dry-run
      Echo the content on the current tty, but do not place it into any
      terminal input buffer; delays operate normally.  This can be used to
      practice the demo or to evaluate timing.

-P <message> | --pause-confirm <message>
      Instructs `velocityper` to emit a message on the managing terminal and
      prompt for a return before continuing, allowing the demonstration to
      pause and continue as needed.

-p <delay> | --pause <delay>
      Pause the output for the period provided.

-s | --skip
      Don't make output or do delays.  Multiple invocations of this option
      toggle between skipping and not skipping.  This option can be used
      in input files to turn on and off operations, effectively commenting
      out section of data.

-t <terminal> | --tty <terminal>
      Provides a terminal to use for pushing input data, allowing one ter-
      minal to handling the prompting while running the demonstration in a
      second terminal.  This option requires super-user permissions, since
      it opens security concerns.  infinityIntroduce a basic delay after
      each character, slowing the rate as required to make the text entry
      approximate human typing.

Escape Sequences

The velocityper utility accepts format strings that can contain escape sequences, which must be preceeded by a backslash. The following table lists the sup- porting escape sequences:

EscSeq  Operation
\a       Emit alarm ('^G')
\b       Emit backspace ('^H')
\e       Emit escape ('^[')
\f       Emit formfeed ('^L')
\n       Emit newline ('^N')
\p       Pause for period from --pause option
\P       Pause for confirmation
\r       Emit carriage return ('^R')
\t       Emit TAB ('^')
\u{num}  Emit UTF-8 encoding of the code point
\xYZ     Emit hex character (0xYZ)
\x{hex}  Emit a series of two-digit hex values

File Format

The --file option allows content to be placed in a file, using the following syntax:

# lines that start with '#' are comments
# blank lines are ignored

# lines that start with '-' are command line options:
-p 1000 --wait=100

# lines that start with '' escape these:
\ and this backslash is as well

# any other lines are stuffed
# the trailing newline is turned into a RETURN ('\r')
# to avoid this, end the line with a backslash
these two lines turn into \
one single line

# other backslash characters are supported:
#    '\b', '\n', '\p', '\r', '\t', etc

# Turn off stuffing and waiting, set pause to one second
# and emit a series of alternating pluses and minuses
-n --wait=0 --pause=1s
+\p\b-\p\b+\p\b-\p\b+\p\b-\p\b+\p\b-\p\b+\p\b-\p\b+\p\b-\p\bDone

Examples

This example places six lines of data into the input buffer:

velocityper -b 70ms -w 30ms -l 150ms "one\rtwo\rthree\rfour\rfive\rsix\r"

This example places three lines of data into the input buffer, pausing one second after each line:

velocityper -w 5 -b 95 -p 1s "echo 1\r\pecho 2\r\pecho 3\r"

This example does not stuff data ('-n') but emits on stdout the characters "cdef" on one line and the UTF-8 smiley face on a second line:

velocityper -n 'one: \x{63646566}\ntwo: \u{263A}\n'

This example uses a file to perform a demo in another terminal:

sudo velocityper --tty /dev/pts/1 --file my-demo.ks

The file would contain the full demo content:

#
# Demo for JUNOS
#  These lines will drive a demo of the JUNOS CLI
# First we adjust the timers to human-ish values
-w 20ms -b 70ms -l 200ms
# Then we pause to wait until I'm ready to start
-P "ready to start demo"
configure private
edit protocols bgp group foo neighbor 1.2.3.4
# Pause again to explain what's about to happen
-P "bgp complete
set apply-macro foo one 1
set apply-macro foo two 2
show
# pause to allow more discussion
-P "apply complete"
set apply-lock user phil
up 1
protect neighbor 1.2.3.4
# These skip lines are used to comment out a section of data,
# which can be done using comments, but if the section is
# lengthy, then adding two "--skip" lines might be easier.
--skip
show
--skip
# At each of these pauses, I can talk as well as type on
# the terminal, mixing canned and interactive content.
# But I might need to restore some state (e.g. location) before
# hitting RETURN in the other terminal.
-P "protect complete
show | compare
-P "done"

Historical Notes

This command will not work under OpenBSD, due to removal of TIOCSTI:

https://undeadly.org/cgi?action=article&sid=20170701132619

Author

velocityper was written by Phil Shafer <[email protected]>.

velocityper's People

Watchers

Phil Shafer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.