lib/planter/prompt.rb in planter-cli-3.0.5 vs lib/planter/prompt.rb in planter-cli-3.0.7

- old
+ new

@@ -71,10 +71,12 @@ ## ## @param integer [Boolean] Round result to nearest integer ## ## @return [Number] numeric response ## + ## @api private + ## def read_number(integer: false) default = @default ? " {xw}[{xbw}#{@default}{xw}]" : '' Planter.notify("{by}#{@prompt} {xc}({bw}#{@min}{xc}-{bw}#{@max}{xc})#{default}") res = @gum ? read_number_gum : read_line_tty @@ -90,10 +92,12 @@ ## ## Parse a date value into a date string ## ## @return [String] date string ## + ## @api private + ## def date_default default = @value || @default return nil unless default if default =~ /'.*?'/ @@ -118,10 +122,12 @@ ## ## @param prompt [String] The prompt ## ## @return [Date] Parsed Date object ## + ## @api private + ## def read_date(prompt: nil) prompt ||= @prompt default = date_default default = default ? " {bw}[#{default}]" : '' @@ -139,10 +145,12 @@ ## asking for a secondary response ## until a blank entry is given ## ## @return [String] the single-line response ## + ## @api private + ## def read_line(prompt: nil) return @default if Planter.accept_defaults || ENV['PLANTER_DEBUG'] prompt ||= @prompt default = @default ? " {bw}[#{@default}]" : '' @@ -162,10 +170,12 @@ ## asking for a secondary response ## until a blank entry is given ## ## @return [String] the multi-line response ## + ## @api private + ## def read_lines(prompt: nil) prompt ||= @prompt save = @gum ? 'Ctrl-J for newline, Enter' : 'Ctrl-D' Planter.notify("{by}#{prompt} {xc}({bw}#{save}{xc} to save)'", newline: false) res = @gum ? read_multiline_gum(prompt) : read_mutliline_tty @@ -178,10 +188,12 @@ ## ## Read a numeric entry using gum ## ## @return [String] String response ## + ## @api private + ## def read_number_gum trap('SIGINT') { exit! } res = `gum input --placeholder "#{@min}-#{@max}"`.strip return nil if res.strip.empty? @@ -191,10 +203,12 @@ ## ## Read a single line entry using TTY::Reader ## ## @return [String] String response ## + ## @api private + ## def read_line_tty trap('SIGINT') { exit! } reader = TTY::Reader.new res = reader.read_line('>> ').strip return nil if res.empty? @@ -205,10 +219,12 @@ ## ## Read a single line entry using gum ## ## @return [String] String response ## + ## @api private + ## def read_line_gum trap('SIGINT') { exit! } res = `gum input --placeholder "(blank to use default)"`.strip return nil if res.empty? @@ -218,10 +234,12 @@ ## ## Read a multiline entry using TTY::Reader ## ## @return [string] multiline input ## + ## @api private + ## def read_mutliline_tty trap('SIGINT') { exit! } reader = TTY::Reader.new res = reader.read_multiline res.join("\n").strip @@ -230,10 +248,12 @@ ## ## Read a multiline entry using gum ## ## @return [string] multiline input ## + ## @api private + ## def read_multiline_gum(prompt) trap('SIGINT') { exit! } width = TTY::Screen.cols > 80 ? 80 : TTY::Screen.cols `gum write --placeholder "#{prompt}" --width #{width} --char-limit 0`.strip end @@ -266,10 +286,10 @@ numeric = choices.first =~ /^\(?\d+\.?\)? / keys = choices.to_options(numeric) values = choices.to_values.map(&:clean_value) end - die('Choice(s) without selector, please edit config') unless keys.all?(&:has_selector?) + die('Choice(s) without selector, please edit config') unless keys.all?(&:selector?) default = case default_response.to_s when /^\d+$/ values[default.to_i] when /^[a-z]$/i