From 4d77944785e5d4c7f9f77401197a1fbf72abbbad Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 23 Jan 2025 23:31:06 +0900 Subject: [PATCH 1/2] Page overflow calculation should work even with winsize=[0,0] --- lib/irb/pager.rb | 2 +- test/irb/test_pager.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/irb/pager.rb b/lib/irb/pager.rb index 16ff30cf8..89e1e7100 100644 --- a/lib/irb/pager.rb +++ b/lib/irb/pager.rb @@ -189,7 +189,7 @@ def write(text) end end @buffer.clear - @buffer << @lines.pop unless @lines.last.end_with?("\n") + @buffer << @lines.pop if !@lines.empty? && !@lines.last.end_with?("\n") @col = Reline::Unicode.calculate_width(@buffer, true) end if overflow || @lines.size > @height || (@lines.size == @height && @col > 0) diff --git a/test/irb/test_pager.rb b/test/irb/test_pager.rb index 0fad94da3..5a61b0e91 100644 --- a/test/irb/test_pager.rb +++ b/test/irb/test_pager.rb @@ -70,5 +70,17 @@ def test_callback_delay assert_equal 'a' * 1000 + 'bcd', out.string assert_equal [:before_delay, [:callback_called, ['a' * 10] * 4], :after_delay], actual_events end + + def test_zero_width + out = IRB::Pager::PageOverflowIO.new(0, 0, ->*{}) + 100.times { out.write 'a' } + assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string] + out = IRB::Pager::PageOverflowIO.new(10, 0, ->*{}) + 100.times { out.write 'a' } + assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string] + out = IRB::Pager::PageOverflowIO.new(0, 10, ->*{}) + 100.times { out.write 'a' } + assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string] + end end end From d436dcba43d73d11733f3cb81eb435f42dc8bc70 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 23 Jan 2025 23:33:09 +0900 Subject: [PATCH 2/2] InputMethod#winsize fallback to [24, 80] if width or height is zero --- lib/irb/input-method.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 260d9a1cb..890ea10fc 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -26,10 +26,11 @@ def gets def winsize if instance_variable_defined?(:@stdout) && @stdout.tty? - @stdout.winsize - else - [24, 80] + winsize = @stdout.winsize + # If width or height is 0, something is wrong. + return winsize unless winsize.include? 0 end + [24, 80] end # Whether this input method is still readable when there is no more data to