mfm/src/fzf.cr

24 lines
504 B
Crystal
Raw Normal View History

2023-10-22 21:23:56 +00:00
module GX
class Fzf
def self.run(list : Array(String)) : String
input = IO::Memory.new
input.puts list.join("\n")
input.rewind
output = IO::Memory.new
error = STDERR
process = Process.new("fzf", ["--ansi"], input: input, output: output, error: error)
unless process.wait.success?
STDERR.puts "Error executing fzf: #{error.to_s.strip}".colorize(:red)
exit(1)
end
result = output.to_s.strip #.split.first?
end
end
end