ruby-changes:69980
From: Yusuke <ko1@a...>
Date: Tue, 30 Nov 2021 11:44:08 +0900 (JST)
Subject: [ruby-changes:69980] eac347fdb0 (master): lib/pp.rb (PP.pp): Use io/console's winsize by default
https://git.ruby-lang.org/ruby.git/commit/?id=eac347fdb0 From eac347fdb04023e1a365d84a8c163263cc7a5904 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Tue, 30 Nov 2021 11:42:06 +0900 Subject: lib/pp.rb (PP.pp): Use io/console's winsize by default [Feature #12913] --- lib/pp.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pp.rb b/lib/pp.rb index 72480e53047..c164110508a 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -61,6 +61,15 @@ require 'prettyprint' https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L61 # Tanaka Akira <akr@f...> class PP < PrettyPrint + def PP.width_for(out) + begin + require 'io/console' + _, width = out.winsize + rescue LoadError, NoMethodError, Errno::ENOTTY + end + (width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1 + end + # Outputs +obj+ to +out+ in pretty printed format of # +width+ columns in width. # @@ -68,7 +77,7 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L77 # If +width+ is omitted, 79 is assumed. # # PP.pp returns +out+. - def PP.pp(obj, out=$>, width=79) + def PP.pp(obj, out=$>, width=width_for(out)) q = PP.new(out, width) q.guard_inspect_key {q.pp obj} q.flush -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/