summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-09-03 22:51:15 +0900
committeraycabta <aycabta@gmail.com>2020-09-14 02:13:18 +0900
commit8f9b1902f48b413bd161666630c878ad58418c04 (patch)
tree5a27c1126d53504a84a72fce349a25b4f47d7264 /lib
parente468d9f49ca34f713c030c623f655a40370e186d (diff)
[ruby/irb] Omit output if first line of multiline is too long
https://github.com/ruby/irb/commit/0feeae38c5
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index e020aa6..d8e1209 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -750,10 +750,20 @@ module IRB
str = @context.inspect_last_value
multiline_p = str.include?("\n")
if omit
+ winwidth = @context.io.winsize.last
if multiline_p
- str.gsub!(/(\A.*?\n).*/m, "\\1...")
+ first_line = str.split("\n").first
+ result = @context.newline_before_multiline_output? ? (@context.return_format % first_line) : first_line
+ output_width = Reline::Unicode.calculate_width(result, true)
+ diff_size = output_width - Reline::Unicode.calculate_width(first_line, true)
+ if diff_size.positive? and output_width > winwidth
+ lines, _ = Reline::Unicode.split_by_width(first_line, winwidth - diff_size - 3)
+ str = "%s...\e[0m" % lines.first
+ multiline_p = false
+ else
+ str.gsub!(/(\A.*?\n).*/m, "\\1...")
+ end
else
- winwidth = @context.io.winsize.last
output_width = Reline::Unicode.calculate_width(@context.return_format % str, true)
diff_size = output_width - Reline::Unicode.calculate_width(str, true)
if diff_size.positive? and output_width > winwidth