added minimal documentation
This commit is contained in:
parent
50f446b772
commit
8d1ea41c79
16
demo.sh
16
demo.sh
@ -1,4 +1,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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}"
|
TYPE_SPEED="${TYPE_SPEED:-15}"
|
||||||
PROMPT_TIMEOUT="${PROMPT_TIMEOUT:--1}"
|
PROMPT_TIMEOUT="${PROMPT_TIMEOUT:--1}"
|
||||||
@ -6,6 +16,9 @@ PROMPT_TIMEOUT="${PROMPT_TIMEOUT:--1}"
|
|||||||
function simtyping()
|
function simtyping()
|
||||||
{ pv -qL $(($TYPE_SPEED+$((-2 + RANDOM%5)))); }
|
{ pv -qL $(($TYPE_SPEED+$((-2 + RANDOM%5)))); }
|
||||||
|
|
||||||
|
function type()
|
||||||
|
{ printf "$*" | simtyping; }
|
||||||
|
|
||||||
function wait()
|
function wait()
|
||||||
{
|
{
|
||||||
[ "$PROMPT_TIMEOUT" == "-1" ] &&
|
[ "$PROMPT_TIMEOUT" == "-1" ] &&
|
||||||
@ -13,9 +26,6 @@ function wait()
|
|||||||
read -rst "$PROMPT_TIMEOUT"
|
read -rst "$PROMPT_TIMEOUT"
|
||||||
}
|
}
|
||||||
|
|
||||||
function type()
|
|
||||||
{ printf "$*" | simtyping; }
|
|
||||||
|
|
||||||
function prompt()
|
function prompt()
|
||||||
{
|
{
|
||||||
def="\033[0;00m"
|
def="\033[0;00m"
|
||||||
|
Loading…
Reference in New Issue
Block a user