website/cmd/ttyshot: Remove wait-for-{str,re}.

The wait-for-str op is no longer needed since the ttyshot procedure will now end
gracefully.

The wait-for-re op seems to never been used in the first place.

Also add a -v flag that enables verbose logging, although there is no logging
call yet.
This commit is contained in:
Qi Xiao 2022-08-03 22:06:23 +01:00
parent 8e6399ebff
commit e089bbc4b0
5 changed files with 8 additions and 29 deletions

View File

@ -10,7 +10,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"
@ -165,7 +164,6 @@ func spawnElvish(homePath string, tty *os.File) (<-chan error, error) {
func executeScript(script []op, ctrl *os.File) {
implicitEnter := true
nextCmdNum := 1
for _, op := range script {
switch op.typ {
case opText:
@ -193,16 +191,7 @@ func executeScript(script []op, ctrl *os.File) {
implicitEnter = false
case opWaitForPrompt:
waitForOutput(ctrl, promptMarker,
func(content []byte) bool { return bytes.Contains(content, []byte(promptMarker)) })
nextCmdNum++
case opWaitForString:
expected := op.val.(string)
waitForOutput(ctrl, expected,
func(content []byte) bool { return bytes.Contains(content, []byte(expected)) })
case opWaitForRegexp:
expected := op.val.(*regexp.Regexp)
waitForOutput(ctrl, expected.String(),
func(content []byte) bool { return expected.Match(content) })
func(bs []byte) bool { return bytes.HasSuffix(bs, []byte(promptMarker)) })
default:
panic("unhandled op")
}

View File

@ -15,6 +15,8 @@ package main
import (
"flag"
"fmt"
"io"
"log"
"os"
)
@ -29,6 +31,7 @@ func main() {
func run(args []string) error {
fs := flag.NewFlagSet("ttyshot", flag.ExitOnError)
outFlag := fs.String("o", "", "output file (defaults to spec-path + .html)")
verboseFlag := fs.Bool("v", false, "enable verbose logging")
saveRawFlag := fs.String("save-raw", "", "if non-empty, save output of capture-pane to this file")
fs.Usage = func() {
fmt.Fprintln(fs.Output(), "Usage: ttyshot [flags] spec-path")
@ -41,6 +44,10 @@ func run(args []string) error {
os.Exit(1)
}
if !*verboseFlag {
log.SetOutput(io.Discard)
}
specPath := fs.Args()[0]
content, err := os.ReadFile(specPath)
if err != nil {

View File

@ -4,7 +4,6 @@ package main
import (
"errors"
"regexp"
"strings"
)
@ -22,8 +21,6 @@ const (
opAlt // send an alt sequence
opCtrl // send a control character
opWaitForPrompt // wait for prompt marker
opWaitForRegexp // wait for sequence of bytes matching the regexp
opWaitForString // wait for the literal sequence of bytes
)
type op struct {
@ -103,17 +100,5 @@ func parseDirective(directive string) (op, error) {
return op{opLeft, nil}, nil
}
if strings.HasPrefix(directive, "wait-for-re ") {
re, err := regexp.Compile(string(directive[12:]))
if err != nil {
return op{}, errors.New("invalid wait-for-re value: " + string(directive[12:]))
}
return op{opWaitForRegexp, re}, nil
}
if strings.HasPrefix(directive, "wait-for-str ") {
return op{opWaitForString, directive[13:]}, nil
}
return op{}, errors.New("unrecognized directive: " + string(directive))
}

View File

@ -2,4 +2,3 @@ randint 1 7
//prompt
//no-enter
//up
//wait-for-str HISTORY #

View File

@ -5,4 +5,3 @@ randint 1 7
//no-enter
ra
//up
//wait-for-str HISTORY #