1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/terminal_info.rb
☈king 14283aa51f Adjusting ls output for voluminous output
The previous table output was geared mostly for `ls _pry_`, which isn't
a common of hierarchy. After feedback from users such as @envygeeks, we
found a few tweaks that would help the really-small layers such as those
found in Rails or in small classes, namely:

- Rolling it up onto one line, if possible
- Highlighting the heading in the colors familiar to users of GNU ls for
  "directory" style

Additionally, I took the opportunity for toning down the
private/protected method colors, because before they were green and
yellow, now they're both "muted terminal blue"

Without the ability to really get in and really distinguish colors (e.g.
using 256 colors), giving "protected" such a loud color seems wrong.

Before recoloring:
  https://github.com/pry/pry/issues/813#issuecomment-12355179
After:
  https://github.com/pry/pry/issues/813#issuecomment-12355941
2013-01-17 23:15:31 +00:00

48 lines
1.5 KiB
Ruby

class Pry::TerminalInfo
# Return a pair of [rows, columns] which gives the size of the window.
#
# If the window size cannot be determined, return nil.
def self.screen_size
rows, cols = actual_screen_size
if rows && cols
[rows.to_i, cols.to_i]
else
nil
end
end
# Return a screen width or a default if it fails.
def self.width! default = 80
(screen_size || [nil, default])[1]
end
def self.actual_screen_size
[
# Some readlines also provides get_screen_size.
# Readline comes before IO#winsize because jruby sometimes defaults winsize to [25, 80]
readline_screen_size,
# io/console adds a winsize method to IO streams.
# rescue nil for jruby 1.7.0 [jruby/jruby#354]
$stdout.tty? && $stdout.respond_to?(:winsize) && ($stdout.winsize rescue nil),
# Otherwise try to use the environment (this may be out of date due
# to window resizing, but it's better than nothing).
[ENV["LINES"] || ENV["ROWS"], ENV["COLUMNS"]],
# If the user is running within ansicon, then use the screen size
# that it reports (same caveats apply as with ROWS and COLUMNS)
ENV['ANSICON'] =~ /\((.*)x(.*)\)/ && [$2, $1],
].detect do |(_, cols)|
cols.to_i > 0
end
end
def self.readline_screen_size
Readline.get_screen_size if Readline.respond_to?(:get_screen_size)
rescue Java::JavaLang::NullPointerException
# This rescue won't happen on jrubies later than:
# https://github.com/jruby/jruby/pull/436
nil
end
end