Method: NA.request_input

Defined in:
lib/na/next_action.rb

.request_input(options, prompt: 'Enter text') ⇒ Object

Request terminal input from user, readline style

Parameters:

  • options (Hash)

    The options

  • prompt (String) (defaults to: 'Enter text')

    The prompt



2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
# File 'lib/na/next_action.rb', line 2077

def request_input(options, prompt: 'Enter text')
  if $stdin.isatty && TTY::Which.exist?('gum') && (options[:tagged].nil? || options[:tagged].empty?)
    opts = [%(--placeholder "#{prompt}"),
            '--char-limit=500',
            "--width=#{TTY::Screen.columns}"]
    `gum input #{opts.join(' ')}`.strip
  elsif $stdin.isatty && options[:tagged].empty?
    NA.notify("#{NA.theme[:prompt]}#{prompt}:")
    reader.read_line(NA::Color.template("#{NA.theme[:filename]}> #{NA.theme[:action]}")).strip
  end
end