diff options
author | 邹云慧 <1300698769@qq.com> | 2018-04-06 18:42:02 +0800 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2018-05-12 21:22:25 -0300 |
commit | acf3d81f8fbeca7efde6b65d4c92c04ab9b70216 (patch) | |
tree | e249c2fdada5666778104b8af4444d6b26e724e2 /lib | |
parent | 4d236c63e8c5ebcd72b2ee10a73da9108cb553fb (diff) | |
download | highline-acf3d81f8fbeca7efde6b65d4c92c04ab9b70216.tar.gz |
about shell and gather
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/highline.rb | 21 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/highline/menu.rb | 10 |
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index 1e195e6..3e60cd3 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -257,7 +257,16 @@ class HighLine return unless selected if menu.shell - selection, details = selected + if menu.gather + selection = [] + details = [] + selected.each do |value| + selection << value[0] + details << value[1] + end + else + selection, details = selected + end else selection = selected end @@ -533,9 +542,11 @@ class HighLine break if ["\n", "\r"].include? character # honor backspace and delete - if character == "\b" + if character == "\b" || character == "\u007F" chopped = line.chop! output_erase_char if chopped && question.echo + elsif character == "\e" + ignore_arrow_key else line << character say_last_char_or_echo_char(line, question) @@ -561,6 +572,12 @@ class HighLine end end + def ignore_arrow_key + 2.times do + terminal.get_character + end + end + def say_last_char_or_echo_char(line, question) @output.print(line[-1]) if question.echo == true @output.print(question.echo) if question.echo && question.echo != true diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index 5f73cd7..8029b49 100644..100755 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -472,16 +472,22 @@ class HighLine selected_items = selections.map do |selection| find_item_from_selection(items, selection) end + index = 0 selected_items.map do |selected_item| - value_for_selected_item(selected_item, details) + value = value_for_selected_item(selected_item, self.shell ? details[index] : nil) + index += 1 + value end end def value_for_hash_selections(items, selections, details) # Find the selected items and return in hash form + index = 0 selections.each_with_object({}) do |(key, selection), memo| selected_item = find_item_from_selection(items, selection) - memo[key] = value_for_selected_item(selected_item, details) + value = value_for_selected_item(selected_item, self.shell ? details[index] : nil) + index += 1 + memo[key] = value end end |