From 972cc993cad8bd32d0468c082f7e410aabd1e8cb Mon Sep 17 00:00:00 2001 From: aycabta Date: Wed, 6 Oct 2021 02:56:14 +0900 Subject: [PATCH] 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')