Class: Downup::Base
- Inherits:
-
Object
- Object
- Downup::Base
- Defined in:
- lib/downup/base.rb
Overview
The main interface to use Downup
initialize a Downup::Base object with all your desired options and call #prompt to retrieve the user selection.
Instance Attribute Summary collapse
-
#selected_position ⇒ Object
readonly
Returns the value of attribute selected_position.
Instance Method Summary collapse
-
#initialize(options:, flash_message: nil, flash_color: :green, default_color: :brown, selected_color: :magenta, multi_select_selector: "√", selector: "‣", type: :default, stdin: $stdin, stdout: $stdout, header_proc: Proc.new{}) ⇒ Base
constructor
A new instance of Base.
-
#prompt(position = 0) ⇒ String
Prompts the user to make selection from the options the object with initialized with.
Constructor Details
#initialize(options:, flash_message: nil, flash_color: :green, default_color: :brown, selected_color: :magenta, multi_select_selector: "√", selector: "‣", type: :default, stdin: $stdin, stdout: $stdout, header_proc: Proc.new{}) ⇒ Base
Returns a new instance of Base.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/downup/base.rb', line 38 def initialize(options:, flash_message: nil, flash_color: :green, default_color: :brown, selected_color: :magenta, multi_select_selector: "√", selector: "‣", type: :default, stdin: $stdin, stdout: $stdout, header_proc: Proc.new{}) @options = @flash_color = flash_color @flash_message = @default_color = default_color @selected_color = selected_color @selector = selector @type = type @header_proc = header_proc @stdin = stdin @stdout = stdout @colonel = Kernel @multi_select_selector = multi_select_selector @multi_selected_positions = [] end |
Instance Attribute Details
#selected_position ⇒ Object (readonly)
Returns the value of attribute selected_position.
15 16 17 |
# File 'lib/downup/base.rb', line 15 def selected_position @selected_position end |
Instance Method Details
#prompt(position = 0) ⇒ String
Prompts the user to make selection from the options the object with initialized with.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/downup/base.rb', line 69 def prompt(position = 0) @selected_position = position_selector(position) colonel.system("clear") header_proc.call print_flash Downup::OptionsPrinter.new( options: , selected_position: @selected_position, multi_selected_positions: @multi_selected_positions, multi_select_selector: multi_select_selector, default_color: default_color, selected_color: selected_color, selector: selector, stdin: stdin, stdout: stdout, ). stdout.print "\n> " input = read_char process_input input end |