ruby-changes:67371
From: aycabta <ko1@a...>
Date: Tue, 31 Aug 2021 05:26:42 +0900 (JST)
Subject: [ruby-changes:67371] 282f7ce896 (master): [ruby/reline] Use DialogRenderInfo struct
https://git.ruby-lang.org/ruby.git/commit/?id=282f7ce896 From 282f7ce8961b7493f46c48ef74b16fd9c7f2a158 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 31 Aug 2021 01:56:18 +0900 Subject: [ruby/reline] Use DialogRenderInfo struct https://github.com/ruby/reline/commit/ac6f652a39 --- lib/reline.rb | 3 ++- lib/reline/line_editor.rb | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 1109d7a..9ba6c3c 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -18,6 +18,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L18 Key = Struct.new('Key', :char, :combined_char, :with_meta) CursorPos = Struct.new(:x, :y) + DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, keyword_init: true) class Core ATTR_READER_NAMES = %i( @@ -221,7 +222,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L222 context.clear context.push(cursor_pos_to_render, result, pointer) end - [cursor_pos_to_render, result, pointer, nil] + DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer) } Reline::DEFAULT_DIALOG_CONTEXT = Array.new diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f93731d..ca37611 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -566,12 +566,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L566 return end dialog.set_cursor_pos(cursor_column, @first_line_started_from + @started_from) - pos, result, pointer, bg = dialog.call + dialog_render_info = dialog.call old_dialog_contents = dialog.contents old_dialog_column = dialog.column old_dialog_vertical_offset = dialog.vertical_offset - if result and not result.empty? - dialog.contents = result + if dialog_render_info and dialog_render_info.contents and not dialog_render_info.contents.empty? + dialog.contents = dialog_render_info.contents dialog.contents = dialog.contents[0...DIALOG_HEIGHT] if dialog.contents.size > DIALOG_HEIGHT else dialog.lines_backup = { @@ -587,32 +587,32 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L587 end upper_space = @first_line_started_from - @started_from lower_space = @highest_in_all - @first_line_started_from - @started_from - 1 - dialog.column = pos.x + dialog.column = dialog_render_info.pos.x diff = (dialog.column + DIALOG_WIDTH) - (@screen_size.last - 1) if diff > 0 dialog.column -= diff end - if (lower_space + @rest_height - pos.y) >= DIALOG_HEIGHT - dialog.vertical_offset = pos.y + 1 + if (lower_space + @rest_height - dialog_render_info.pos.y) >= DIALOG_HEIGHT + dialog.vertical_offset = dialog_render_info.pos.y + 1 elsif upper_space >= DIALOG_HEIGHT - dialog.vertical_offset = pos.y + -(DIALOG_HEIGHT + 1) + dialog.vertical_offset = dialog_render_info.pos.y + -(DIALOG_HEIGHT + 1) else - if (lower_space + @rest_height - pos.y) < DIALOG_HEIGHT - scroll_down(DIALOG_HEIGHT + pos.y) - move_cursor_up(DIALOG_HEIGHT + pos.y) + if (lower_space + @rest_height - dialog_render_info.pos.y) < DIALOG_HEIGHT + scroll_down(DIALOG_HEIGHT + dialog_render_info.pos.y) + move_cursor_up(DIALOG_HEIGHT + dialog_render_info.pos.y) end - dialog.vertical_offset = pos.y + 1 + dialog.vertical_offset = dialog_render_info.pos.y + 1 end Reline::IOGate.hide_cursor reset_dialog(dialog, old_dialog_contents, old_dialog_column, old_dialog_vertical_offset) move_cursor_down(dialog.vertical_offset) Reline::IOGate.move_cursor_column(dialog.column) dialog.contents.each_with_index do |item, i| - if i == pointer + if i == dialog_render_info.pointer bg_color = '45' else - if bg - bg_color = bg + if dialog_render_info.bg_color + bg_color = dialog_render_info.bg_color else bg_color = '46' end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/