added minimal documentation

This commit is contained in:
Kjistóf 2017-10-08 21:25:16 +02:00
parent 50f446b772
commit 8d1ea41c79

16
demo.sh
View File

@ -1,4 +1,14 @@
#!/usr/bin/env bash
#
# A handy collection of tools to create interactive demos:
# type(): simulates typing its arguments
# execute(): simuates typing then executing its arguments in a shell
# wait(): waits for user input with optional timeout
# cmd(): gives control to user until she enters 'end' (or for a single command if you pass an argument).
#
# Helpers (internal stuff):
# simtyping(): let's data piped to it through at rates similar to typing
# prompt(): prints a nice colored prompt
TYPE_SPEED="${TYPE_SPEED:-15}"
PROMPT_TIMEOUT="${PROMPT_TIMEOUT:--1}"
@ -6,6 +16,9 @@ PROMPT_TIMEOUT="${PROMPT_TIMEOUT:--1}"
function simtyping()
{ pv -qL $(($TYPE_SPEED+$((-2 + RANDOM%5)))); }
function type()
{ printf "$*" | simtyping; }
function wait()
{
[ "$PROMPT_TIMEOUT" == "-1" ] &&
@ -13,9 +26,6 @@ function wait()
read -rst "$PROMPT_TIMEOUT"
}
function type()
{ printf "$*" | simtyping; }
function prompt()
{
def="\033[0;00m"