summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2025-01-22 10:39:55 +0900
committertomoya ishida <tomoyapenguin@gmail.com>2025-01-22 23:08:34 +0900
commitc066453118f5ecfb86282e02398a4da344e1cd79 (patch)
tree7d13b031bea6ec3026df4abb2b7b3f943df45270 /lib
parent9ce642c282921ed3f75d5ac0fd6d468f384b3ae4 (diff)
[ruby/irb] Fix pager preview with escape sequence and newlines
(https://github.com/ruby/irb/pull/1069) https://github.com/ruby/irb/commit/a139562a07
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12612
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/pager.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/irb/pager.rb b/lib/irb/pager.rb
index 65303e5ac1..16ff30cf89 100644
--- a/lib/irb/pager.rb
+++ b/lib/irb/pager.rb
@@ -152,11 +152,13 @@ module IRB
end
def puts(text = '')
+ text = text.to_s unless text.is_a?(String)
write(text)
write("\n") unless text.end_with?("\n")
end
def write(text)
+ text = text.to_s unless text.is_a?(String)
@string << text
if @multipage
if @delay_until && Time.now > @delay_until
@@ -171,23 +173,24 @@ module IRB
text = text[0, overflow_size]
overflow = true
end
-
@buffer << text
- @col += Reline::Unicode.calculate_width(text)
+ @col += Reline::Unicode.calculate_width(text, true)
if text.include?("\n") || @col >= @width
@buffer.lines.each do |line|
wrapped_lines = Reline::Unicode.split_by_width(line.chomp, @width).first.compact
wrapped_lines.pop if wrapped_lines.last == ''
@lines.concat(wrapped_lines)
- if @lines.empty?
- @lines << "\n"
- elsif line.end_with?("\n")
- @lines[-1] += "\n"
+ if line.end_with?("\n")
+ if @lines.empty? || @lines.last.end_with?("\n")
+ @lines << "\n"
+ else
+ @lines[-1] += "\n"
+ end
end
end
@buffer.clear
@buffer << @lines.pop unless @lines.last.end_with?("\n")
- @col = Reline::Unicode.calculate_width(@buffer)
+ @col = Reline::Unicode.calculate_width(@buffer, true)
end
if overflow || @lines.size > @height || (@lines.size == @height && @col > 0)
@first_page_lines = @lines.take(@height)