planck 2017-08-18

playing around with my editor project, I’m trying to figure out a clean way to read a character from stdin. I’ve ended up with

(let [ch ((:raw-read core/*in*))]
  ...)

which to me wasn’t quite obvious, and might also be somewhat reaching for internals.

It seams like in Clojure, the equvialent would be something like

(let [ch (.read *in*)] 
...)

(ns keystroke.core
  (:import [jline.console ConsoleReader]))

(defn show-keystroke []
  (print "Enter a keystroke: ")
  (flush)
  (let [cr (ConsoleReader.)
        keyint (.readCharacter cr)]
    (println (format "Got %d ('%c')!" keyint (char keyint)))))

eg using jline.

looking at the planck implementation, it seems as if (and it seems to work) I should just use (js/PLANCK_RAW_READ_STDIN)

which still feels a bit low-level.

Any thoughts?

@slipset Perhaps there could be a planck.core/read-character which delegates to a js/PLANCK_READ_CHARACTER which does the right thing (perhaps things along the line of get_next_char that is in linenoise.c)

@rhinocratic has joined the channel