From 996bfec64bd6d98e53bfe42248ef0a9a6fcac275 Mon Sep 17 00:00:00 2001 From: aycabta Date: Wed, 6 Oct 2021 00:09:03 +0900 Subject: [PATCH 1/3] Rename DIALOG_HEIGHT with DIALOG_DEFAULT_HEIGHT --- lib/reline/line_editor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 574793d67a..f68018e85b 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -622,7 +622,7 @@ def add_dialog_proc(name, p, context = nil) @dialogs << Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context)) end - DIALOG_HEIGHT = 20 + DIALOG_DEFAULT_HEIGHT = 20 private def render_dialog(cursor_column) @dialogs.each do |dialog| render_each_dialog(dialog, cursor_column) @@ -662,7 +662,7 @@ def add_dialog_proc(name, p, context = nil) else dialog.width = dialog.contents.map { |l| calculate_width(l, true) }.max end - height = dialog_render_info.height || DIALOG_HEIGHT + height = dialog_render_info.height || DIALOG_DEFAULT_HEIGHT height = dialog.contents.size if dialog.contents.size < height if dialog.contents.size > height if dialog.pointer From 972cc993cad8bd32d0468c082f7e410aabd1e8cb Mon Sep 17 00:00:00 2001 From: aycabta Date: Wed, 6 Oct 2021 02:56:14 +0900 Subject: [PATCH 2/3] Cut off the excess on narrow screen --- lib/reline/line_editor.rb | 4 ++++ test/reline/yamatanooroti/test_rendering.rb | 26 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f68018e85b..008085c36e 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -709,6 +709,10 @@ def add_dialog_proc(name, p, context = nil) end Reline::IOGate.hide_cursor dialog.width += @block_elem_width if dialog.scrollbar_pos + if dialog.column < 0 + dialog.column = 0 + dialog.width = @screen_size.last + end reset_dialog(dialog, old_dialog) move_cursor_down(dialog.vertical_offset) Reline::IOGate.move_cursor_column(dialog.column) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 0bcd70700c..78128a3fcf 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -1072,6 +1072,32 @@ def test_dialog_callback_returns_nil EOC end + def test_dialog_narrower_than_screen + start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-long}, startup_message: 'Multiline REPL.') + write('S' + "\C-i" * 3) + close + assert_screen(<<~'EOC') + Multiline R + EPL. + prompt> Sym + String + Struct █ + Symbol █ + StopIterat█ + SystemCall█ + SystemExit█ + SystemStac█ + ScriptErro█ + SyntaxErro█ + Signal █ + SizedQueue█ + Set + SecureRand + Socket + StringIO + EOC + end + def test_rerender_argument_prompt_after_pasting start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.') write('abcdef') From 44cd35e65d23867d8787792e4e681ea9378feda2 Mon Sep 17 00:00:00 2001 From: aycabta Date: Wed, 6 Oct 2021 03:25:53 +0900 Subject: [PATCH 3/3] Add a test for narrow screen without scrollbar --- test/reline/yamatanooroti/test_rendering.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 78128a3fcf..08a6171786 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -1073,6 +1073,22 @@ def test_dialog_callback_returns_nil end def test_dialog_narrower_than_screen + start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.') + close + assert_screen(<<~'EOC') + Multiline R + EPL. + prompt> + Ruby is... + A dynamic, + language wi + and product + syntax that + easy to wri + EOC + end + + def test_dialog_narrower_than_screen_with_scrollbar start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-long}, startup_message: 'Multiline REPL.') write('S' + "\C-i" * 3) close