This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-30
Channels
- # announcements (20)
- # asami (26)
- # babashka (10)
- # babashka-sci-dev (18)
- # beginners (81)
- # biff (6)
- # calva (6)
- # cider (1)
- # clerk (1)
- # clj-kondo (34)
- # clojure (50)
- # clojure-belgium (1)
- # clojure-berlin (6)
- # clojure-europe (20)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-uk (2)
- # clojurescript (1)
- # clr (4)
- # community-development (3)
- # data-science (8)
- # datomic (3)
- # gratitude (1)
- # honeysql (6)
- # instaparse (2)
- # jobs (1)
- # jobs-discuss (13)
- # kaocha (7)
- # london-clojurians (1)
- # lsp (6)
- # malli (8)
- # matcher-combinators (9)
- # missionary (3)
- # nbb (8)
- # off-topic (20)
- # pathom (16)
- # polylith (2)
- # practicalli (3)
- # rdf (1)
- # re-frame (7)
- # reagent (3)
- # releases (2)
- # reveal (6)
- # rewrite-clj (22)
- # shadow-cljs (64)
- # tools-build (7)
- # xtdb (13)
loving nbb. tying to create an ink app, but struggling to get the useInput
to work. Anyone have any luck getting user input in an Ink TUI? The following doesn't work:
(ns app
(:require
["ink" :as ink :refer [render Text Box useInput]]))
(defonce state (r/atom {:j false
:k true}))
(defn handle-input [state input _]
(println "here")
(case input
"j" (swap! state update :j not)
(swap! state update :k not)))
(defn root [state]
[useInput (partial handle-input state)]
[:> Text (str @state)]
)
(render (r/as-element [root state]))
(defn main-loop []
(js/setTimeout main-loop 3000))
(main-loop)
@U0CGFT70T This seems to work:
(ns example
(:require
["ink" :as ink :refer [render Text Box useInput]]
[reagent.core :as r]))
(defonce state (r/atom {:j false
:k true}))
(defn handle-input [state input _]
(println "here" input)
(case input
"j" (swap! state update :j not)
(swap! state update :k not)))
(defn input []
(useInput (fn [input key]
(handle-input state input key)))
[:> Text {:color "green"} (str @state)])
(render (r/as-element [:f> input]))
(defn main-loop []
(js/setTimeout main-loop 3000))
(main-loop)
See https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md for details on how to call "function components"
@U04V15CAJ Thanks so much I'll go give that a try. Thanks for all the great work you do and sharing it... I'll see if I can send you a patreon or something?
@U0CGFT70T 🙏 Does Github Sponsors work for you? https://github.com/sponsors/borkdude OpenCollective is also possible https://opencollective.com/babashka Or ko-fi: https://ko-fi.com/borkdude