Created
May 13, 2017 14:02
-
-
Save borkdude/07b97a3d7fb9183598b7b2a940e35407 to your computer and use it in GitHub Desktop.
Standard input with lumo / node / ClojureScript
This file contains hidden or 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
#!/usr/bin/env lumo | |
(defn greeting! [name] | |
(println (str "Hello " name "!"))) | |
(def stdinput (atom "")) | |
(js/require "process") | |
(.setEncoding js/process.stdin "utf8") | |
(.on js/process.stdin "data" | |
(fn [data] | |
(swap! stdinput #(str % data)))) | |
(.on js/process.stdin "end" | |
(fn [] | |
(swap! stdinput (fn [s] | |
(subs s 0 (dec (count s))))) | |
(greeting! @stdinput))) | |
;; echo foo | ./script.cljs -> "Hello foo!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment