diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-11-22 14:06:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-22 14:06:50 -0400 |
commit | edfba257560f9bd779f5ef1c87a0e3d697e3decb (patch) | |
tree | 542006cdada53a2d3e8fa803257dd2cd72fa60d5 | |
parent | 413ad89036ab535e53642c66333e9622323fdf32 (diff) | |
parent | 0f1b0eb6e31ea8a2f3dce11dbbc181a886ea0696 (diff) | |
download | highline-2.0.0.pre.develop.14.tar.gz |
Merge pull request #222 from JEG2/issue_221v2.0.0.pre.develop.14
Fix #221 - Consistent behaviour for agree with readline = true
-rw-r--r-- | Changelog.md | 3 | ||||
-rwxr-xr-x | lib/highline.rb | 1 | ||||
-rwxr-xr-x | lib/highline/question.rb | 2 | ||||
-rwxr-xr-x | lib/highline/terminal.rb | 8 | ||||
-rw-r--r-- | lib/highline/version.rb | 2 | ||||
-rw-r--r-- | test/acceptance/at_readline_agree.rb | 18 |
6 files changed, 27 insertions, 7 deletions
diff --git a/Changelog.md b/Changelog.md index 53dd055..2e316ff 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ Below is a complete listing of changes for each revision of HighLine. +### 2.0.0-develop.14 / 2017-11-21 +* PR #222 / I #221 - Fix inconsistent behaviour when using agree with readline (@abinoam, @ailisp) + ### 2.0.0-develop.13 / 2017-11-05 * PR #219 - Make possible to use a callable as response (@abinoam) diff --git a/lib/highline.rb b/lib/highline.rb index 6ece3dc..1e195e6 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -196,6 +196,7 @@ class HighLine q.responses[:not_valid] = 'Please enter "yes" or "no".' q.responses[:ask_on_error] = :question q.character = character + q.completion = %w[yes no] yield q if block_given? end diff --git a/lib/highline/question.rb b/lib/highline/question.rb index 27b18b4..6dd1293 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -575,7 +575,7 @@ class HighLine # @param highline [HighLine] context # @return [void] def show_question(highline) - highline.say(self) unless readline && (echo == true && !limit) + highline.say(self) end # Returns an echo string that is adequate for this Question settings. diff --git a/lib/highline/terminal.rb b/lib/highline/terminal.rb index cd1d3dc..d736369 100755 --- a/lib/highline/terminal.rb +++ b/lib/highline/terminal.rb @@ -98,9 +98,7 @@ class HighLine def get_line_with_readline(question, highline) require "readline" # load only if needed - question_string = highline.render_statement(question) - - raw_answer = readline_read(question_string, question) + raw_answer = readline_read(question) if !raw_answer && highline.track_eof? raise EOFError, "The input stream is exhausted." @@ -113,7 +111,7 @@ class HighLine # @param prompt [String] Readline prompt # @param question [HighLine::Question] question from where to get # autocomplete candidate strings - def readline_read(prompt, question) + def readline_read(question) # prep auto-completion unless question.selection.empty? Readline.completion_proc = lambda do |str| @@ -126,7 +124,7 @@ class HighLine $VERBOSE = nil raw_answer = run_preserving_stty do - Readline.readline(prompt, true) + Readline.readline("", true) end $VERBOSE = old_verbose diff --git a/lib/highline/version.rb b/lib/highline/version.rb index 1def22d..3bd94a3 100644 --- a/lib/highline/version.rb +++ b/lib/highline/version.rb @@ -2,5 +2,5 @@ class HighLine # The version of the installed library. - VERSION = "2.0.0-develop.13".freeze + VERSION = "2.0.0-develop.14".freeze end diff --git a/test/acceptance/at_readline_agree.rb b/test/acceptance/at_readline_agree.rb new file mode 100644 index 0000000..0a94180 --- /dev/null +++ b/test/acceptance/at_readline_agree.rb @@ -0,0 +1,18 @@ +# coding: utf-8 + +require_relative "acceptance_test" + +HighLine::AcceptanceTest.check do |t| + t.desc = + "This step checks if the readline works well with agree.\n" \ + "You should press <tab> and readline should give the default " \ + "(yes/no) options to autocomplete." + + t.action = proc do + answer = agree("Do you agree?") { |q| q.readline = true } + puts "You've entered -> #{answer} <-" + end + + t.question = + "Did HighLine#agree worked well using question.readline = true (y/n)? " +end |