lib/howzit/prompt.rb in howzit-2.0.2 vs lib/howzit/prompt.rb in howzit-2.0.3
- old
+ new
@@ -2,19 +2,21 @@
module Howzit
# Command line prompt utils
module Prompt
class << self
- def yn(prompt, default = true)
- return default if !$stdout.isatty
+ def yn(prompt, default: true)
+ return default unless $stdout.isatty
- system 'stty cbreak'
- yn = color_single_options(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'
+ return default if Howzit.options[:default]
+
+ system 'stty cbreak'
+ yn = color_single_options(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.empty? ? default : res =~ /y/i
end
def color_single_options(choices = %w[y n])
out = []