lib/make_menu.rb in make_menu-2.0.0 vs lib/make_menu.rb in make_menu-2.1.0

- old
+ new

@@ -1,7 +1,8 @@ # frozen_string_literal: true +require_relative 'make_menu/console/prompter' require_relative 'make_menu/console/color_string' require_relative 'make_menu/menu' require 'tty-screen' @@ -10,7 +11,42 @@ trap('SIGINT') { throw StandardError } def self.run(makefile = './Makefile', &block) MakeMenu::Menu.new(makefile).run(&block) + end + + def self.prompt(text = nil, obscure: false, value_from_file: nil) + if (preamble = ARGV[0]) + if text.nil? + if preamble.include?("\n") + parts = preamble.split("\n") + preamble = parts[0..-2].join("\n") + text = parts[-1] + puts preamble + else + text = preamble + end + end + end + + if value_from_file + begin + input = Console::Prompter.prompt_and_save text, file: value_from_file, obscure: obscure + puts (obscure ? ('*' * input.decolor.size) : input).green.underline + + rescue Console::Prompter::PressedEscape + puts '(not updated)'.red + end + else + begin + input = Console::Prompter.prompt text, obscure: obscure + puts (obscure ? ('*' * input.decolor.size) : input).green.underline + $stderr.puts input + rescue Console::Prompter::PressedEscape + puts '(not updated)'.red + end + end + + input end end