Rename AUTO to CYCLE on key c and relay browser keys to stdin
This commit is contained in:
@@ -169,6 +169,14 @@ func run(runFor time.Duration, at string, out io.Writer, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go io.Copy(stdin, os.Stdin)
|
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 {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -52,6 +53,12 @@ const page = `<!doctype html>
|
|||||||
await new Promise(r => setTimeout(r, 1000));
|
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>
|
</script>
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -70,6 +77,9 @@ var (
|
|||||||
|
|
||||||
clientsMu sync.RWMutex
|
clientsMu sync.RWMutex
|
||||||
clients = make(map[chan []byte]bool)
|
clients = make(map[chan []byte]bool)
|
||||||
|
|
||||||
|
consoleMu sync.Mutex
|
||||||
|
console io.Writer
|
||||||
)
|
)
|
||||||
|
|
||||||
func serveStream() error {
|
func serveStream() error {
|
||||||
@@ -93,10 +103,27 @@ func serveStream() error {
|
|||||||
fmt.Fprint(w, page)
|
fmt.Fprint(w, page)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/frames", frames)
|
mux.HandleFunc("/frames", frames)
|
||||||
|
mux.HandleFunc("/keys", keys)
|
||||||
go http.Serve(ln, mux)
|
go http.Serve(ln, mux)
|
||||||
return nil
|
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
|
// 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
|
// dumb buffer and fails to map on every frame; each error reads once, not at
|
||||||
// frame rate.
|
// frame rate.
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ func run(aName, bName string) (err error) {
|
|||||||
switch b {
|
switch b {
|
||||||
case ' ', 'r':
|
case ' ', 'r':
|
||||||
kickMeasure()
|
kickMeasure()
|
||||||
case 'a':
|
case 'c':
|
||||||
autoOn, autoAnchor = !autoOn, time.Now()
|
autoOn, autoAnchor = !autoOn, time.Now()
|
||||||
}
|
}
|
||||||
case <-disp.fb.flips:
|
case <-disp.fb.flips:
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ func (d *display) drawAutoButton(on bool, frac float64) {
|
|||||||
if on {
|
if on {
|
||||||
c = uiAccent
|
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 {
|
func (d *display) tapAuto(x, y int, down bool) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user