Last active
December 15, 2015 10:19
-
-
Save pbrisbin/5245051 to your computer and use it in GitHub Desktop.
Hide/capture input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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