Last active
July 1, 2021 15:21
-
-
Save borkdude/fafdff8da1d90833457617a12b769728 to your computer and use it in GitHub Desktop.
Create a NodeJS CLI app using Reagent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
Author
borkdude
commented
Jun 1, 2018
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