Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
PP.width_for
(untyped out) -> ::Integer
width_for(out)
lib/pp.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/pp.rb, line 79
def PP.width_for(out)
begin
require 'io/console'
_, width = out.winsize
rescue LoadError, NoMethodError, SystemCallError
end
(width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1
end
Returns the usable width for out. As the width of out:
-
If
outis assigned to a tty device, its width is used. -
Otherwise, or it could not get the value, the
COLUMNenvironment variable is assumed to be set to the width. -
If
COLUMNis not set to a non-zero number, 80 is assumed.
And finally, returns the above width value - 1.
-
This -1 is for Windows command prompt, which moves the cursor to the next line if it reaches the last column.