diff --git a/harness/main.go b/harness/main.go index 3152f09..b7d84d2 100644 --- a/harness/main.go +++ b/harness/main.go @@ -169,6 +169,14 @@ func run(runFor time.Duration, at string, out io.Writer, args []string) error { return err } go io.Copy(stdin, os.Stdin) + consoleMu.Lock() + console = stdin + consoleMu.Unlock() + defer func() { + consoleMu.Lock() + console = nil + consoleMu.Unlock() + }() if err := cmd.Start(); err != nil { return err } diff --git a/harness/stream.go b/harness/stream.go index fae75c1..9e16266 100644 --- a/harness/stream.go +++ b/harness/stream.go @@ -7,6 +7,7 @@ import ( "image" "image/color" "image/png" + "io" "net" "net/http" "os" @@ -52,6 +53,12 @@ const page = ` await new Promise(r => setTimeout(r, 1000)); } })(); +addEventListener('keydown', e => { + if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) { + e.preventDefault(); + fetch('keys', {method: 'POST', body: e.key}); + } +}); ` @@ -70,6 +77,9 @@ var ( clientsMu sync.RWMutex clients = make(map[chan []byte]bool) + + consoleMu sync.Mutex + console io.Writer ) func serveStream() error { @@ -93,10 +103,27 @@ func serveStream() error { fmt.Fprint(w, page) }) mux.HandleFunc("/frames", frames) + mux.HandleFunc("/keys", keys) go http.Serve(ln, mux) return nil } +func keys(w http.ResponseWriter, r *http.Request) { + b, err := io.ReadAll(r.Body) + if err != nil { + return + } + consoleMu.Lock() + defer consoleMu.Unlock() + if console == nil { + http.Error(w, "no run to type into", http.StatusServiceUnavailable) + return + } + if _, err := console.Write(b); err != nil { + http.Error(w, err.Error(), http.StatusServiceUnavailable) + } +} + // Between runs the crtc scans out the console framebuffer, which is not a // dumb buffer and fails to map on every frame; each error reads once, not at // frame rate. diff --git a/main.go b/main.go index 9807a2c..f6938df 100644 --- a/main.go +++ b/main.go @@ -374,7 +374,7 @@ func run(aName, bName string) (err error) { switch b { case ' ', 'r': kickMeasure() - case 'a': + case 'c': autoOn, autoAnchor = !autoOn, time.Now() } case <-disp.fb.flips: diff --git a/ui.go b/ui.go index a489814..7ebd77d 100644 --- a/ui.go +++ b/ui.go @@ -277,7 +277,7 @@ func (d *display) drawAutoButton(on bool, frac float64) { if on { c = uiAccent } - d.fillButton(d.autoBtn, frac, "AUTO", c, c) + d.fillButton(d.autoBtn, frac, "CYCLE", c, c) } func (d *display) tapAuto(x, y int, down bool) bool {