Skip to content

Commit b37c1c2

Browse files
authored
Zero winsize bugfix (#1073)
* Page overflow calculation should work even with winsize=[0,0] * InputMethod#winsize fallback to [24, 80] if width or height is zero
1 parent 095a1f7 commit b37c1c2

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/irb/input-method.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def gets
2626

2727
def winsize
2828
if instance_variable_defined?(:@stdout) && @stdout.tty?
29-
@stdout.winsize
30-
else
31-
[24, 80]
29+
winsize = @stdout.winsize
30+
# If width or height is 0, something is wrong.
31+
return winsize unless winsize.include? 0
3232
end
33+
[24, 80]
3334
end
3435

3536
# Whether this input method is still readable when there is no more data to

lib/irb/pager.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def write(text)
189189
end
190190
end
191191
@buffer.clear
192-
@buffer << @lines.pop unless @lines.last.end_with?("\n")
192+
@buffer << @lines.pop if !@lines.empty? && !@lines.last.end_with?("\n")
193193
@col = Reline::Unicode.calculate_width(@buffer, true)
194194
end
195195
if overflow || @lines.size > @height || (@lines.size == @height && @col > 0)

test/irb/test_pager.rb

+12
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,17 @@ def test_callback_delay
7070
assert_equal 'a' * 1000 + 'bcd', out.string
7171
assert_equal [:before_delay, [:callback_called, ['a' * 10] * 4], :after_delay], actual_events
7272
end
73+
74+
def test_zero_width
75+
out = IRB::Pager::PageOverflowIO.new(0, 0, ->*{})
76+
100.times { out.write 'a' }
77+
assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string]
78+
out = IRB::Pager::PageOverflowIO.new(10, 0, ->*{})
79+
100.times { out.write 'a' }
80+
assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string]
81+
out = IRB::Pager::PageOverflowIO.new(0, 10, ->*{})
82+
100.times { out.write 'a' }
83+
assert_equal [true, [], 'a' * 100], [out.multipage?, out.first_page_lines, out.string]
84+
end
7385
end
7486
end

0 commit comments

Comments
 (0)