Fork me on GitHub
#planck
<
2017-08-18
>
slipset07:08:39

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

slipset07:08:14

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

slipset07:08:44

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

slipset07:08:32

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

slipset07:08:02

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

slipset07:08:29

(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)))))

slipset07:08:39

eg using jline.

slipset07:08:20

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

slipset07:08:42

which still feels a bit low-level.

slipset07:08:44

Any thoughts?

mfikes13:08:25

@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)