Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/pager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/irb/test_pager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading