lib/terjira/option_support/editor.rb
module Terjira
class Editor
def self.editor_text(content = '')
editor = ENV['EDITOR']
if editor.nil? || editor.empty?
raise 'EDITOR environment variable not found. Please set a default editor.'
end
tmp_file = Tempfile.new('content')
tmp_file.write(content)
tmp_file.close
success = system "#{editor} #{tmp_file.path}"
content = File.read(tmp_file.path) if success
tmp_file.unlink
raise 'Editor returned a non-zero exit code. Something must have gone wrong' unless success
content
end
end
end