Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Last active December 15, 2015 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrisbin/5245051 to your computer and use it in GitHub Desktop.
Save pbrisbin/5245051 to your computer and use it in GitHub Desktop.
Hide/capture input
class InputReader
def initialize
@thread = Thread.new do
check_input
end
end
def check_input
$stdin.each_line do |line|
process_input(line.chomp)
end
end
def process_input(input)
$stdout.puts "You Said: #{input}"
end
def join
@thread.join
end
end
def noecho
original_settings = `stty -g`
`stty -echo`
yield
ensure
`stty #{original_settings}`
end
noecho do
input = InputReader.new
input.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment