garybernhardt / selecta

A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.
MIT License
1.34k stars 81 forks source link

how to use selecta in ruby with $stdin ? #95

Closed gregory closed 8 years ago

gregory commented 8 years ago

Hey @garybernhardt ,

Thx for writing selecta, it's awesome! :)

I was just wondering what would be the best way to use it in combination with $stdin ?

basically, i get a list of array: ['foo', 'bar'] that i'd like to print and use selecta to let the user select the element to assign to a variable through $stdin.

garybernhardt commented 8 years ago

Selecta isn't designed to be used as a library from within other Ruby code. It requires full control of the TTY (and forcefully configures it via stty), so it wouldn't play nicely as a library. It's not installable as a gem for that reason.

However, to use Selecta from a Ruby program, you can always shell out to it via system(), Open3, or some other mechanism. For example, here's me doing it in irb:

$ irb
irb(main):001:0> system("find ~/proj/selecta | selecta")
8290 >
/Users/grb/proj/selecta
...