Fork me on GitHub
#nbb
<
2022-10-06
>
milelo08:10:19

I'm using "zx/question" (js library) in an nbb script. I'm trying to run it now with a repl from calva using jack-in. Script output is sent to the terminal ok but input I enter into the terminal don't seem to be received by the script. Any ideas? Thanks.

borkdude09:10:08

@milelo The way I usually do this, is make a function which accepts the input, then test that function in the REPL and then hook that function up to the thing that reads from stdin. Stdin + nREPL is a bit complicated

milelo09:10:01

Thanks @borkdude, I was beginning to think along those lines as a work around.

milelo11:10:27

@borkdude. I came up with this to solve my zx/question repl issue. An answer can also be provided by the answer function.

(def answer-listener* (atom nil))

(defn answer [answer]
  (if-let [resolve @answer-listener*]
    (resolve (str answer))
    (println "Error: No question."))
  (reset! answer-listener* nil))

(defn question [question]
  (println question)
  (js/Promise.any #js [(zx/question) (js/Promise. #(reset! answer-listener* %))]))

👍 1