ctlseqs/tests/lib/ctlseqs.exp

51 lines
1.3 KiB
Plaintext

#
# Copyright (C) 2021 CismonX <admin@cismon.net>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty, provided the copyright notice and
# this notice are preserved. This file is offered as-is, without any warranty.
#
set ESC "\x1b"
set CSI "$ESC\["
set DCS "${ESC}P"
set ST "$ESC\\"
proc tcsgrep_start args {
global TCSGREP_BIN
set run_cmd [ list $TCSGREP_BIN "-t500" ]
foreach arg $args {
lappend run_cmd [
switch -regexp -matchvar value -- $arg {
verbose { lindex "-v" }
purge { lindex "-p" }
limit=(\\d+) { lindex "-l [ lindex $value 1 ]" }
timeout=(\\d+) { lindex "-t [ lindex $value 1 ]" }
}
]
}
set stty_init { raw -echo }
global spawn_id
spawn {*}$run_cmd
}
proc tcsgrep_stop { } {
global spawn_id
send "\x04"
expect {
-ex "NOSEQ 1 EOT\n" { }
default {
fail "program exited unexpectedly"
}
}
catch wait result
if { [ set exit_code [ lindex $result 3 ] ] } {
fail "program exited with code $exit_code"
}
}
proc random_int { } {
set num [ exec od -An -td -N4 /dev/urandom ]
return [ expr { abs(int($num)) } ]
}