ruby-changes:67310
From: aycabta <ko1@a...>
Date: Sun, 29 Aug 2021 20:30:46 +0900 (JST)
Subject: [ruby-changes:67310] 4b2b10707a (master): [ruby/reline] Implement dynamic selection of candidates
https://git.ruby-lang.org/ruby.git/commit/?id=4b2b10707a From 4b2b10707af564c1d600957a69d89165fa7d11f1 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 27 Aug 2021 01:51:44 +0900 Subject: [ruby/reline] Implement dynamic selection of candidates https://github.com/ruby/reline/commit/e46437df00 --- lib/reline.rb | 13 ++++++++++--- lib/reline/line_editor.rb | 13 +++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index a3f37d1..eb99bd5 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -183,7 +183,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L183 end @dialog_proc = ->() { # autocomplete - if just_cursor_moving + if just_cursor_moving and completion_journey_data.nil? # Auto complete starts only when edited return nil end @@ -191,7 +191,14 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L191 if target.nil? or target.empty? return nil end - result = call_completion_proc_with_checking_args(pre, target, post) + if completion_journey_data and completion_journey_data.list + result = completion_journey_data.list.dup + result.shift + pointer = completion_journey_data.pointer - 1 + else + result = call_completion_proc_with_checking_args(pre, target, post) + pointer = nil + end if result and result.size == 1 and result[0] == target result = nil end @@ -203,7 +210,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L210 else y = 0 end - [Reline::CursorPos.new(x, y), result] + [Reline::CursorPos.new(x, y), result, pointer] } inner_readline(prompt, add_hist, true, &confirm_multiline_termination) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index b449f4f..79f8688 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -514,6 +514,10 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L514 @line_editor.instance_variable_get(:@screen_size).last end + def completion_journey_data + @line_editor.instance_variable_get(:@completion_journey_data) + end + def call instance_exec(&@proc_to_exec) end @@ -533,7 +537,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L537 return end @dialog_proc_scope.set_cursor_pos(cursor_column, @first_line_started_from + @started_from) - pos, result = @dialog_proc_scope.call + pos, result, pointer = @dialog_proc_scope.call old_dialog_contents = @dialog_contents old_dialog_contents_width = @dialog_contents_width old_dialog_column = @dialog_column @@ -582,7 +586,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L586 move_cursor_down(@dialog_vertical_offset) Reline::IOGate.move_cursor_column(@dialog_column) @dialog_contents.each_with_index do |item, i| - @output.write "\e[46m%-#{DIALOG_WIDTH}s\e[49m" % item.slice(0, DIALOG_WIDTH) + if i == pointer + bg_color = '45' + else + bg_color = '46' + end + @output.write "\e[#{bg_color}m%-#{DIALOG_WIDTH}s\e[49m" % item.slice(0, DIALOG_WIDTH) Reline::IOGate.move_cursor_column(@dialog_column) move_cursor_down(1) if i < (@dialog_contents.size - 1) end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/