make delay parametrable
This commit is contained in:
@@ -39,12 +39,30 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
busy()
|
busy()
|
||||||
{
|
{
|
||||||
if [[ -n $1 ]]; then
|
local pattern="ca fe"
|
||||||
local pattern="$@"
|
for arg in "$@"; do
|
||||||
else
|
case "$arg" in
|
||||||
local pattern="ca fe"
|
--delay=*)
|
||||||
fi
|
delay_ms="${arg#*=}"
|
||||||
cat /dev/urandom | hexdump -C | grep "$pattern"
|
if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then
|
||||||
|
disp E "Invalid delay value, must be an integer (milliseconds)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
pattern="$arg"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Convert milliseconds to seconds for 'sleep'
|
||||||
|
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
|
||||||
|
|
||||||
|
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
||||||
|
while read -r line; do
|
||||||
|
echo $line
|
||||||
|
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||||
|
done
|
||||||
unset pattern
|
unset pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user