add -w to cmdline replay

This commit is contained in:
Zhi Wang 2022-01-18 06:35:58 -05:00
parent b673b172f0
commit 0c5915677e
2 changed files with 18 additions and 5 deletions

View File

@ -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)
} }

View File

@ -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 "$@"