mirror of
https://github.com/syssecfsu/witty.git
synced 2024-12-24 19:52:33 +01:00
add a shell command to replay
This commit is contained in:
parent
bd47a3442d
commit
aee1251238
68
cmd/replay/replay.go
Normal file
68
cmd/replay/replay.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
|
)
|
||||||
|
|
||||||
|
type writeRecord struct {
|
||||||
|
Dur time.Duration `json:"Duration"`
|
||||||
|
Data []byte `json:"Data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
log.Fatalln("Usage: replay <recordfile>")
|
||||||
|
}
|
||||||
|
|
||||||
|
fp, err := os.Open(os.Args[1])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Failed to open record file", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
screen := struct {
|
||||||
|
io.Reader
|
||||||
|
io.Writer
|
||||||
|
}{os.Stdin, os.Stdout}
|
||||||
|
|
||||||
|
t := term.NewTerminal(screen, ">")
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
log.Fatalln("Failed to create terminal")
|
||||||
|
}
|
||||||
|
|
||||||
|
w, h, err := term.GetSize(int(os.Stdout.Fd()))
|
||||||
|
|
||||||
|
if (w != 120) || (h != 36) {
|
||||||
|
fmt.Println("Set terminal window to 120x36")
|
||||||
|
os.Stdout.WriteString(`\e[8;50;100t`)
|
||||||
|
}
|
||||||
|
/* if err := term.SetSize(120, 36); err != nil {
|
||||||
|
log.Println("Failed to set terminal size", err)
|
||||||
|
} */
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(fp)
|
||||||
|
|
||||||
|
if decoder == nil {
|
||||||
|
log.Fatalln("Failed to create JSON decoder")
|
||||||
|
}
|
||||||
|
|
||||||
|
for decoder.More() {
|
||||||
|
var record writeRecord
|
||||||
|
|
||||||
|
if err := decoder.Decode(&record); err != nil {
|
||||||
|
log.Println("Failed to decode record", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(record.Dur)
|
||||||
|
t.Write(record.Data)
|
||||||
|
}
|
||||||
|
}
|
4
cmd/replay/run.sh
Executable file
4
cmd/replay/run.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
echo "Try to resize shell with shell command"
|
||||||
|
printf '\e[8;36;120t'
|
||||||
|
clear
|
||||||
|
./replay $1
|
1
go.mod
1
go.mod
@ -23,5 +23,6 @@ require (
|
|||||||
github.com/ugorji/go/codec v1.1.7 // indirect
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -51,6 +51,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
Loading…
Reference in New Issue
Block a user