From 46640b7003f166c035f9c58b9dbdb2ec34e0b39a Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 02:42:00 +0300 Subject: [PATCH 1/2] Fall back when the terminal or COLUMNS width is nonpositive --- lib/pp.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pp.rb b/lib/pp.rb index 798a4f4..3cd0d84 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -82,7 +82,8 @@ def PP.width_for(out) _, width = out.winsize rescue LoadError, NoMethodError, SystemCallError end - (width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1 + width = ENV['COLUMNS'].to_i unless width && width > 0 + (width > 0 ? width : 80) - 1 end # Outputs +obj+ to +out+ in pretty printed format of From 90d942b611e08bd33bf7b09db58628724e67bf81 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 02:43:43 +0300 Subject: [PATCH 2/2] Document positive COLUMNS fallback consistently --- lib/pp.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pp.rb b/lib/pp.rb index 3cd0d84..7536c58 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -69,9 +69,9 @@ class PP < PrettyPrint # Returns the usable width for +out+. # As the width of +out+: # 1. If +out+ is assigned to a tty device, its width is used. - # 2. Otherwise, or it could not get the value, the +COLUMN+ + # 2. Otherwise, or it could not get a positive value, the +COLUMNS+ # environment variable is assumed to be set to the width. - # 3. If +COLUMN+ is not set to a non-zero number, 80 is assumed. + # 3. If +COLUMNS+ is not set to a positive number, 80 is assumed. # # And finally, returns the above width value - 1. # * This -1 is for Windows command prompt, which moves the cursor to