Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active July 1, 2021 15:21
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/fafdff8da1d90833457617a12b769728 to your computer and use it in GitHub Desktop.
Save borkdude/fafdff8da1d90833457617a12b769728 to your computer and use it in GitHub Desktop.
Create a NodeJS CLI app using Reagent
(ns reagent-blessed.core
(:require
[cljs.nodejs :as node :refer [require]]
[react]
[reagent.core :as r]))
(def v8 (js/require "v8"))
(.setFlagsFromString v8 "--no-use_strict")
(def blessed (node/require "blessed"))
(def react-blessed (node/require "react-blessed"))
(node/enable-util-print!)
(def screen (.screen blessed #js {:smartCSR true}))
(def state (r/atom 0))
(defn hello
[]
[:box
{:top "center"
:left "center"
:width "50%"
:height "50%"
:border {:type "line"}
:style {:border {:fg "blue"}}}
(str "Hello world! "
@state)])
(.key screen #js ["up"]
(fn [ch key]
(swap! state inc)))
(.key screen #js ["down"]
(fn [ch key]
(swap! state dec)))
(.key screen #js ["escape"
"q"
"C-c"]
(fn [ch key]
(js/process.exit)))
(.render react-blessed
(r/as-element [hello])
screen)
@borkdude
Copy link
Author

borkdude commented Jun 1, 2018

reagent-blessed

@arichiardi
Copy link

This is very nice thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment