Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring submit action key in select #163

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ac4e83
Add test that demonstrates default list select behaviour
Geekfish May 14, 2021
993ced2
Fix typo in slider and list show_help
Geekfish May 14, 2021
44a179f
Support submit_keys and select_key in (multi_)select
Geekfish May 14, 2021
dce79bf
Fix hints for #select and #multi_select in README
Geekfish May 14, 2021
0a99a13
Rename select to select_choice
Geekfish May 16, 2021
9cb0352
Add enter to default submit keys
Geekfish May 16, 2021
5327ce9
Replace :tab with :ctrl_s as submit key in examples, docs and tests
Geekfish May 16, 2021
b24819d
Allow defining the label of submit keys
Geekfish May 16, 2021
135e62a
Add author handle in CHANGELOG
Geekfish May 16, 2021
395e6b1
Make multi-select select keys an array and allow custom labels
Geekfish May 16, 2021
3fa9f2c
Ensure cross-system compat for EOL chars in custom action keys
Geekfish May 16, 2021
1f1bc73
Rename clashing to conflicting and return exact conflict
Geekfish May 18, 2021
0dd6891
Fix multi-line block formatting and simplify implementation
Geekfish May 18, 2021
3df157e
Improve implementation of ensure_eol_compat
Geekfish May 18, 2021
e1b759d
Add examples and fix param/return types
Geekfish May 18, 2021
94e79a5
Reorder key-related functions in the same cluster
Geekfish May 18, 2021
1bcba3f
Set next version to unreleased and fix contributor name
Geekfish Jun 6, 2021
fd1cbdd
Rename :submit_keys to :confirm_keys
Geekfish Jun 6, 2021
e8bc200
Add support for non-special characters (incl. alphanumeric and symbols)
Geekfish Jun 6, 2021
d3ae0f8
Make default confirm keys for select a constant
Geekfish Jul 20, 2021
b4c71b6
Fix jruby-head bug which seems to ignore when statement
Geekfish Jul 21, 2021
bdbdd2b
Add DSL support for confirm_keys and select_keys
Geekfish Jul 30, 2021
5ec712f
Apply code review suggestions to support splat operator arguments
Geekfish Aug 1, 2021
e805155
Code review fixes
Geekfish Aug 2, 2021
9a70628
More code review fixes
Geekfish Aug 2, 2021
b43a32a
Make submit and select examples consistent, add missing yard option
Geekfish Aug 20, 2021
d42efff
Change conflicting keys error message
Geekfish Aug 20, 2021
9dea17b
Use helpers for confirm_keys DSL test
Geekfish Aug 20, 2021
7dc89e8
Fix yard warnings in list.rb and multi_list.rb
Geekfish Aug 21, 2021
2334b89
Fix hint description in README
Geekfish Aug 21, 2021
44945c4
Remove superfluous backticks from README code blocks
Geekfish Aug 22, 2021
33b4beb
Add missing newlines before code blocks in README
Geekfish Aug 22, 2021
79cd017
Fix help text in README and add key @param descriptions
Geekfish Aug 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/tty/prompt/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def default(*default_values)
#
# @api private
def default_submit_keys
%i[space return].freeze
%i[space return enter].freeze
end

# Select paginator based on the current navigation key
Expand Down Expand Up @@ -177,7 +177,7 @@ def arrows_help
#
# @api private
def key_help_label(key_name)
key_name == :return ? "Enter" : key_name.to_s.capitalize
%i[return enter].include?(key_name) ? "Enter" : key_name.to_s.capitalize
Geekfish marked this conversation as resolved.
Show resolved Hide resolved
end

# Information about keys that submit the selection
Expand All @@ -186,7 +186,7 @@ def key_help_label(key_name)
#
# @api private
def submit_keys_help
labels = @submit_keys.map(&method(:key_help_label))
labels = @submit_keys.map(&method(:key_help_label)).uniq
case labels.length
when 1
labels[0]
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/prompt/multi_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def max(value)
#
# @api private
def default_submit_keys
[:return].freeze
%i[return enter].freeze
end

# Callback fired when a submit key is pressed
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,40 @@ def exit_message(prompt, choice)
expect(actual_prompt_output).to eql(expected_prompt_output)
end

it "filters and chooses entry with enter, with default key config" do
prompt.input << "g" << "\n"
prompt.input.rewind

answer = prompt.select("What size?", %i[Small Medium Large Huge], filter: true)
expect(answer).to eql(:Large)

actual_prompt_output = prompt.output.string
expected_prompt_output =
output_helper("What size?", %w[Small Medium Large Huge], "Small", init: true,
hint: "Press #{up_down} arrow to move, Space or Enter to select and letters to filter") +
output_helper("What size?", %w[Large Huge], "Large", hint: "Filter: \"g\"") +
exit_message("What size?", "Large")

expect(actual_prompt_output).to eql(expected_prompt_output)
end

it "filters and chooses entry with return and enter, with default key config" do
prompt.input << "g" << "\r\n"
prompt.input.rewind

answer = prompt.select("What size?", %i[Small Medium Large Huge], filter: true)
expect(answer).to eql(:Large)

actual_prompt_output = prompt.output.string
expected_prompt_output =
output_helper("What size?", %w[Small Medium Large Huge], "Small", init: true,
hint: "Press #{up_down} arrow to move, Space or Enter to select and letters to filter") +
output_helper("What size?", %w[Large Huge], "Large", hint: "Filter: \"g\"") +
exit_message("What size?", "Large")

expect(actual_prompt_output).to eql(expected_prompt_output)
end

it "filters and chooses entry with space, with default key config" do
prompt.input << "g" << " "
prompt.input.rewind
Expand Down