Skip to content

Instantly share code, notes, and snippets.

@timuruski
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timuruski/c6bad0f0639f85f6b985 to your computer and use it in GitHub Desktop.
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.
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