planck

Planck ClojureScript REPL
slipset 2017-08-18T07:17:39.000031Z

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

slipset 2017-08-18T07:18:14.000192Z

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

slipset 2017-08-18T07:18:44.000162Z

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

slipset 2017-08-18T07:20:32.000258Z

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

slipset 2017-08-18T07:21:02.000136Z

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

slipset 2017-08-18T07:22:18.000208Z

although the the “Clojure Cookbook”, https://www.safaribooksonline.com/library/view/clojure-cookbook/9781449366384/ch04.html suggests

slipset 2017-08-18T07:22:29.000027Z

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

slipset 2017-08-18T07:22:39.000036Z

eg using jline.

slipset 2017-08-18T07:24:20.000020Z

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

slipset 2017-08-18T07:24:42.000182Z

which still feels a bit low-level.

slipset 2017-08-18T07:24:44.000220Z

Any thoughts?

mfikes 2017-08-18T13:31:25.000059Z

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