Class: TTY::Prompt::MultiList Private

Inherits:
List
  • Object
show all
Defined in:
lib/tty/prompt/multi_list.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A class responsible for rendering multi select list menu. Used by TTY::Prompt to display interactive choice menu.

Constant Summary collapse

HELP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'(Use arrow%s keys, press Space to select and Enter to finish)'.freeze

Constants inherited from List

List::PAGE_HELP

Constants included from Symbols

Symbols::KEYS, Symbols::WIN_KEYS

Instance Method Summary collapse

Methods inherited from List

#call, #choice, #choices, #default, #default_help, #enum, #enumerate?, #help, #keydown, #keynum, #keyreturn, #keyup, #marker, #page_help, #page_size, #paginated?, #per_page

Methods included from Symbols

symbols, windows?

Constructor Details

#initialize(prompt, options) ⇒ MultiList

Create instance of TTY::Prompt::MultiList menu.

Parameters:

  • :prompt (Prompt)
  • options (Hash)


20
21
22
23
24
25
26
# File 'lib/tty/prompt/multi_list.rb', line 20

def initialize(prompt, options)
  super
  @selected = []
  @help    = options[:help]
  @default = Array(options[:default])
  @echo = options.fetch(:echo, true)
end

Instance Method Details

#keyspaceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Callback fired when space key is pressed



31
32
33
34
35
36
37
38
# File 'lib/tty/prompt/multi_list.rb', line 31

def keyspace(*)
  active_choice = @choices[@active - 1]
  if @selected.include?(active_choice)
    @selected.delete(active_choice)
  else
    @selected << active_choice
  end
end