Module: Howzit::Prompt
- Included in:
- BuildNotes
- Defined in:
- lib/howzit/prompt.rb
Overview
Command line prompt utils
Instance Method Summary collapse
Instance Method Details
#yn(prompt, default = true) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/howzit/prompt.rb', line 6 def yn(prompt, default = true) return default if !$stdout.isatty system 'stty cbreak' yn = (default ? %w[Y n] : %w[y N]) $stdout.syswrite "\e[1;37m#{prompt} #{yn}\e[1;37m? \e[0m" res = $stdin.sysread 1 res.chomp! puts system 'stty cooked' res =~ /y/i end |