30 lines
766 B
Janet
30 lines
766 B
Janet
(import spork/netrepl)
|
|
(import spork/msg)
|
|
|
|
(defn run-commands [sock args]
|
|
(with [stream (net/connect :unix sock)]
|
|
(def recv- (msg/make-recv stream))
|
|
(def send (msg/make-send stream))
|
|
(send (string/format "\xFF%j" {:auto-flush true :name ""}))
|
|
(defn recv []
|
|
(def ms (recv-))
|
|
(case (ms 0)
|
|
nil ms
|
|
0xFF (do
|
|
(prin (slice ms 1))
|
|
(flush)
|
|
(recv))
|
|
0xFE (slice ms 1))
|
|
ms)
|
|
(def prompt (recv))
|
|
(each arg args
|
|
(send arg)
|
|
(loop [:until (= prompt (recv))]))))
|
|
|
|
(defn main [exe & args]
|
|
(def sock (string (os/getenv "XDG_RUNTIME_DIR") "/censtablo-" (os/getenv "WAYLAND_DISPLAY")))
|
|
(if (empty? args)
|
|
(netrepl/client :unix sock)
|
|
(run-commands sock args)))
|
|
|