I have another question today: Is there a way to invoke a command via planck.shell that prompts for keyboard input? I have a collection of strings and I'd like to send them to the cli tool fzf (https://github.com/junegunn/fzf) which displays them with a fuzzy-finder prompts, but my closest attempt so far does not display anything on the screen:
(def choices "one\ntwo\nthree\n")
(sh "fzf" :in choices)
The problem would be that the stdin and stdout of the sub-process are only visible to Planck
I think I understand your question: You want to send data to the stdin of that subprocess...
yes that's right
See the :in
parameter to planck.shell/sh
In that, you could put a string that has newlines separating each input you want
that is what I did in the example above, and so far so good, but I'm hoping to see the fzf prompt on the screen from which I invoked planck, but it doesn't appear
Ahh, right. Planck has the stdout of that process, which you will only get back later when the process completes via the :out
parameter returned from planck.shell/sh
okay, so I take it that means this is not possible today?
Yeah, with Planck, you can't really get at the input and output streams of the process in a dynamic way.
I think Clojure's sh
command lets you obtain a stream for out
okay, that's alright. I will make do.
do you see any technical reason a fzf-like tool could not be written in planck-compatible cljs?
I don't know what fzf is
You can certainly write a Planck program that prompts for input as it runs
this is a little bit more though, it renders in the terminal a dynamic list of options and as you type it narrows them down to the matches
i'll find a little animation
Oh, to do that, you would need to access individual keypresses I would bet
yes for sure
Planck doesn't currently have a get-keypress
function or something along those lines
I suppose one could be added
https://inconsolation.files.wordpress.com/2014/08/2014-08-05-6m47421-fzf.gif
alright well thanks for your help again Mike. I also want to say that I know there are other cljs-scripting projects out there but because planck can be so easily installed and the apis it ships with are so useful it makes it easier for me to get real things going with it. Thanks for that.
@austin.chamberlin Cool. And like I said, I think a blocking get-keypress
(or some good name) might be useful for writing nifty little programs like that (even terminal based games, etc.)
Feel free to add an issue to Planck... it fundamentally doesn't seem too hard to implement something like that
@austin.chamberlin I might try to add a get-keypress
capability later on tonight. I’m curious, are you interested in using such a thing, and if so, is the nature of your project such that you could make use of a pre-release with the functionality.