summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2023-05-27 23:48:45 +0900
committergit <svn-admin@ruby-lang.org>2023-05-27 14:48:50 +0000
commit5d137a7f77ce1b4ca3514565de41fe8a2cf611a4 (patch)
treeab5e57804ff2d1cfaa643e7db91e6a6f9ffef42b /lib
parentbf1bc5362e5edb2321665e9ce7c5c4e2e7d9f5ef (diff)
[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
Diffstat (limited to 'lib')
-rw-r--r--lib/reline.rb2
-rw-r--r--lib/reline/line_editor.rb10
2 files changed, 11 insertions, 1 deletions
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