nbb

2022-10-06T08:39:19.968199Z

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.

borkdude 2022-10-06T09:03:08.237459Z

@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

2022-10-06T09:09:01.731599Z

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

2022-10-06T11:03:27.137709Z

@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