From 5d137a7f77ce1b4ca3514565de41fe8a2cf611a4 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Sat, 27 May 2023 23:48:45 +0900 Subject: [ruby/reline] Use appropriate dialog height and reduce screen pushup problem (https://github.com/ruby/reline/pull/542) * Provide preferred_dialog_height for dialog positioning * Fix rendering test --- lib/reline.rb | 2 +- lib/reline/line_editor.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/reline.rb b/lib/reline.rb index a128d7347d..fd70ffc9d0 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -260,7 +260,7 @@ module Reline pos: cursor_pos_to_render, contents: result, scrollbar: true, - height: 15, + height: [15, preferred_dialog_height].min, bg_color: 46, pointer_bg_color: 45, fg_color: 37, diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index b6304bc040..2e84ca4d0c 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -562,6 +562,16 @@ class Reline::LineEditor @line_editor.instance_variable_get(:@screen_size).last end + def screen_height + @line_editor.instance_variable_get(:@screen_size).first + end + + def preferred_dialog_height + rest_height = @line_editor.instance_variable_get(:@rest_height) + scroll_partial_screen = @line_editor.instance_variable_get(:@scroll_partial_screen) || 0 + [cursor_pos.y - scroll_partial_screen, rest_height, (screen_height + 6) / 5].max + end + def completion_journey_data @line_editor.instance_variable_get(:@completion_journey_data) end -- cgit v1.2.3