Last active
August 29, 2015 14:01
-
-
Save timuruski/c6bad0f0639f85f6b985 to your computer and use it in GitHub Desktop.
Probably useless, but prompts the user to press any key and then blocks until input is entered. Useful for pausing a program while you go inspect something elsewhere, like a queue or DB or whatever.
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
require 'io/console' | |
class PressAnyKey | |
MESSAGE = 'Press any key to continue...' | |
def initialize(console: nil, message: MESSAGE) | |
console ||= File.open('/dev/tty', 'w+') | |
console.puts message | |
console.raw { |io| io.readchar rescue nil } | |
rescue | |
warn "Couldn't connect to console!" | |
end | |
end | |
if $0 == __FILE__ | |
puts "Starting..." | |
PressAnyKey.new(message: 'Wait for it...') | |
puts "...done!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment