planck

Planck ClojureScript REPL
2019-10-29T15:56:05.011400Z

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)

mfikes 2019-10-29T15:57:11.012200Z

The problem would be that the stdin and stdout of the sub-process are only visible to Planck

mfikes 2019-10-29T15:57:47.012800Z

I think I understand your question: You want to send data to the stdin of that subprocess...

2019-10-29T15:58:21.013Z

yes that's right

mfikes 2019-10-29T15:58:45.013700Z

See the :in parameter to planck.shell/sh

mfikes 2019-10-29T15:59:06.014300Z

In that, you could put a string that has newlines separating each input you want

2019-10-29T16:00:24.015600Z

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

mfikes 2019-10-29T16:01:16.016500Z

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

2019-10-29T16:02:51.017Z

okay, so I take it that means this is not possible today?

mfikes 2019-10-29T16:03:54.018100Z

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

2019-10-29T16:04:46.018400Z

okay, that's alright. I will make do.

2019-10-29T16:05:49.019200Z

do you see any technical reason a fzf-like tool could not be written in planck-compatible cljs?

mfikes 2019-10-29T16:06:08.019400Z

I don't know what fzf is

mfikes 2019-10-29T16:06:58.020200Z

You can certainly write a Planck program that prompts for input as it runs

2019-10-29T16:07:53.021200Z

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

2019-10-29T16:08:02.021500Z

i'll find a little animation

mfikes 2019-10-29T16:08:26.021900Z

Oh, to do that, you would need to access individual keypresses I would bet

2019-10-29T16:09:04.022100Z

yes for sure

mfikes 2019-10-29T16:09:35.022600Z

Planck doesn't currently have a get-keypress function or something along those lines

mfikes 2019-10-29T16:09:45.022800Z

I suppose one could be added

2019-10-29T16:15:59.026Z

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.

mfikes 2019-10-29T16:17:47.026900Z

@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.)

mfikes 2019-10-29T16:18:23.027400Z

Feel free to add an issue to Planck... it fundamentally doesn't seem too hard to implement something like that

mfikes 2019-10-29T20:09:56.029100Z

@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.