# frozen_string_literal: true module Howzit # Command line prompt utils module Prompt class << self def yn(prompt, default = true) return default if !$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' res =~ /y/i end def color_single_options(choices = %w[y n]) out = [] choices.each do |choice| case choice when /[A-Z]/ out.push(Color.template("{bg}#{choice}{xg}")) else out.push(Color.template("{w}#{choice}")) end end Color.template("{g}[#{out.join('/')}{g}]{x}") end def options_list(matches) counter = 1 puts matches.each do |match| printf("%2d ) %