module Gish::InputHelpers

Public Instance Methods

capture_editor_input(content=nil) click to toggle source
# File lib/gish/helpers/input_helpers.rb, line 17
def capture_editor_input(content=nil)
  unique_file = "/tmp/#{SecureRandom.hex}"
  File.open(unique_file, 'w+'){|f| f.write(content) }

  command = "#{Gish.editor} #{unique_file} < `tty` > `tty`"
  %x{#{command}}
  ouput = %x{cat #{unique_file}}
  
  File.delete(unique_file)
  ouput.length < 1 ? nil : ouput
end
confirm(message) click to toggle source
# File lib/gish/helpers/input_helpers.rb, line 12
def confirm(message)
  print message
  STDIN.gets.chomp == 'y'
end
prompt(message, opts={}) click to toggle source
# File lib/gish/helpers/input_helpers.rb, line 6
def prompt(message, opts={})
  print message
  input = opts[:masked] ? STDIN.noecho(&:gets) : STDIN.gets
  input.chomp
end