Rename AUTO to CYCLE on key c and relay browser keys to stdin
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user