mirror of
https://github.com/syssecfsu/witty.git
synced 2024-11-01 09:39:26 +01:00
add -w to cmdline replay
This commit is contained in:
parent
b673b172f0
commit
0c5915677e
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -16,11 +17,19 @@ type writeRecord struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
var wait uint
|
||||||
log.Fatalln("Usage: replay <recordfile>")
|
|
||||||
|
flag.UintVar(&wait, "w", 2000, "Max wait time between outputs")
|
||||||
|
flag.UintVar(&wait, "wait", 2000, "Max wait time between outputs")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
left := flag.Args()
|
||||||
|
|
||||||
|
if len(left) != 1 {
|
||||||
|
log.Fatalln("Usage: replay -w/wait time <recordfile>")
|
||||||
}
|
}
|
||||||
|
|
||||||
fp, err := os.Open(os.Args[1])
|
fp, err := os.Open(left[0])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Failed to open record file", err)
|
log.Fatalln("Failed to open record file", err)
|
||||||
@ -31,7 +40,7 @@ func main() {
|
|||||||
io.Writer
|
io.Writer
|
||||||
}{os.Stdin, os.Stdout}
|
}{os.Stdin, os.Stdout}
|
||||||
|
|
||||||
t := term.NewTerminal(screen, ">")
|
t := term.NewTerminal(screen, "$")
|
||||||
|
|
||||||
if t == nil {
|
if t == nil {
|
||||||
log.Fatalln("Failed to create terminal")
|
log.Fatalln("Failed to create terminal")
|
||||||
@ -61,6 +70,10 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if record.Dur > time.Duration(wait)*time.Millisecond {
|
||||||
|
record.Dur = time.Duration(wait) * time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(record.Dur)
|
time.Sleep(record.Dur)
|
||||||
t.Write(record.Data)
|
t.Write(record.Data)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
echo "Try to resize shell with shell command"
|
echo "Try to resize shell with shell command"
|
||||||
printf '\e[8;36;120t'
|
printf '\e[8;36;120t'
|
||||||
clear
|
clear
|
||||||
$(dirname $0)/replay $1
|
$(dirname $0)/replay "$@"
|
Loading…
Reference in New Issue
Block a user