From 4d7cefcaa471802ac774223ff16305ef2e033ff3 Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Oct 2021 03:43:21 +0900 Subject: [PATCH 1/5] Display doc dialog in gaps on narrow screen --- lib/irb/input-method.rb | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index c91a99b56..bcc156774 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -365,14 +365,35 @@ def auto_indent(&block) end return nil if doc.nil? width = 40 + + x = cursor_pos_to_render.x + autocomplete_dialog.width + if x + width > screen_width + old_width = screen_width - (x + 0) + new_x = autocomplete_dialog.column - width + new_x = 0 if new_x < 0 + new_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width + if old_width.positive? and new_width.positive? + if old_width >= new_width + width = old_width + else + width = new_width + x = new_x + end + elsif old_width.positive? and new_width.negative? + width = old_width + elsif old_width.negative? and new_width.positive? + width = new_width + x = new_x + else # Both are negative width. + return nil + end + end formatter = RDoc::Markup::ToAnsi.new formatter.width = width dialog.trap_key = alt_d message = 'Press Alt+d to read the full document' contents = [message] + doc.accept(formatter).split("\n") - x = cursor_pos_to_render.x + autocomplete_dialog.width - x = autocomplete_dialog.column - width if x + width >= screen_width y = cursor_pos_to_render.y DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49') } From a23a88b8c98faf9ba3f7698be497c3f56f93d3eb Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Oct 2021 10:21:55 +0900 Subject: [PATCH 2/5] Specify whether to show the doc dialog on the left or right side by using variable names --- lib/irb/input-method.rb | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index bcc156774..709c9c9bf 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -366,27 +366,31 @@ def auto_indent(&block) return nil if doc.nil? width = 40 - x = cursor_pos_to_render.x + autocomplete_dialog.width - if x + width > screen_width - old_width = screen_width - (x + 0) - new_x = autocomplete_dialog.column - width - new_x = 0 if new_x < 0 - new_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width - if old_width.positive? and new_width.positive? - if old_width >= new_width - width = old_width + right_x = cursor_pos_to_render.x + autocomplete_dialog.width + if right_x + width > screen_width + right_width = screen_width - (right_x + 0) + left_x = autocomplete_dialog.column - width + left_x = 0 if left_x < 0 + left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width + if right_width.positive? and left_width.positive? + if right_width >= left_width + width = right_width + x = right_x else - width = new_width - x = new_x + width = left_width + x = left_x end - elsif old_width.positive? and new_width.negative? - width = old_width - elsif old_width.negative? and new_width.positive? - width = new_width - x = new_x + elsif right_width.positive? and left_width.negative? + width = right_width + x = right_x + elsif right_width.negative? and left_width.positive? + width = left_width + x = left_x else # Both are negative width. return nil end + else + x = right_x end formatter = RDoc::Markup::ToAnsi.new formatter.width = width From f34da7fa04cf453438ecf39393f41c81285d2337 Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Oct 2021 10:24:55 +0900 Subject: [PATCH 3/5] Calculate right side doc dialog width correctly --- lib/irb/input-method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 709c9c9bf..8281c6210 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -368,7 +368,7 @@ def auto_indent(&block) right_x = cursor_pos_to_render.x + autocomplete_dialog.width if right_x + width > screen_width - right_width = screen_width - (right_x + 0) + right_width = screen_width - (right_x + 1) left_x = autocomplete_dialog.column - width left_x = 0 if left_x < 0 left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width From 5df6e1f027dcb24cb9dba261d078a7bc98428f43 Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Oct 2021 10:26:23 +0900 Subject: [PATCH 4/5] Determine left and right when the width of either side is zero correctly --- lib/irb/input-method.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 8281c6210..4917a8fe7 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -380,10 +380,10 @@ def auto_indent(&block) width = left_width x = left_x end - elsif right_width.positive? and left_width.negative? + elsif right_width.positive? and left_width <= 0 width = right_width x = right_x - elsif right_width.negative? and left_width.positive? + elsif right_width <= 0 and left_width.positive? width = left_width x = left_x else # Both are negative width. From ac471ee14ef249f197346f2ec657ce0a8014c67d Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Oct 2021 10:28:44 +0900 Subject: [PATCH 5/5] Add tests for truncated show doc dialog But pending them now because they need dummy document data to show doc. --- test/irb/yamatanooroti/test_rendering.rb | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb index ac6df30c6..7ed98b11c 100644 --- a/test/irb/yamatanooroti/test_rendering.rb +++ b/test/irb/yamatanooroti/test_rendering.rb @@ -170,6 +170,52 @@ def test_symbol_with_backtick EOC end + def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right + pend "Needs a dummy document to show doc" + write_irbrc <<~'LINES' + IRB.conf[:PROMPT][:MY_PROMPT] = { + :PROMPT_I => "%03n> ", + :PROMPT_N => "%03n> ", + :PROMPT_S => "%03n> ", + :PROMPT_C => "%03n> " + } + IRB.conf[:PROMPT_MODE] = :MY_PROMPT + puts 'start IRB' + LINES + start_terminal(4, 19, %W{ruby -I/home/aycabta/ruby/reline/lib -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB') + write("Str\C-i") + close + assert_screen(<<~EOC) + 001> String + StringPress A + StructString + of byte + EOC + end + + def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_left + pend "Needs a dummy document to show doc" + write_irbrc <<~'LINES' + IRB.conf[:PROMPT][:MY_PROMPT] = { + :PROMPT_I => "%03n> ", + :PROMPT_N => "%03n> ", + :PROMPT_S => "%03n> ", + :PROMPT_C => "%03n> " + } + IRB.conf[:PROMPT_MODE] = :MY_PROMPT + puts 'start IRB' + LINES + start_terminal(4, 12, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB') + write("Str\C-i") + close + assert_screen(<<~EOC) + 001> String + PressString + StrinStruct + of by + EOC + end + private def write_irbrc(content) File.open(@irbrc_file, 'w') do |f| f.write content