Rename AUTO to CYCLE on key c and relay browser keys to stdin

This commit is contained in:
flamingcow
2026-08-31 09:02:16 -07:00
parent 5b1eee2699
commit ea272e489c
4 changed files with 37 additions and 2 deletions
+8
View File
@@ -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
}
+27
View File
@@ -7,6 +7,7 @@ import (
"image"
"image/color"
"image/png"
"io"
"net"
"net/http"
"os"
@@ -52,6 +53,12 @@ const page = `<!doctype html>
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});
}
});
</script>
`
@@ -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.
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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 {