Sha256: 66918027fce45e61c2aa55ad129503c8292933267be374edd96940f404792779

Contents?: true

Size: 1.01 KB

Versions: 83

Compression:

Stored size: 1.01 KB

Contents

class Thor
  module Shell
    module Terminal
      DEFAULT_TERMINAL_WIDTH = 80

      class << self
        # This code was copied from Rake, available under MIT-LICENSE
        # Copyright (c) 2003, 2004 Jim Weirich
        def terminal_width
          result = if ENV["THOR_COLUMNS"]
            ENV["THOR_COLUMNS"].to_i
          else
            unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH
          end
          result < 10 ? DEFAULT_TERMINAL_WIDTH : result
        rescue
          DEFAULT_TERMINAL_WIDTH
        end

        def unix?
          RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris)/i
        end

      private

        # Calculate the dynamic width of the terminal
        def dynamic_width
          @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
        end

        def dynamic_width_stty
          `stty size 2>/dev/null`.split[1].to_i
        end

        def dynamic_width_tput
          `tput cols 2>/dev/null`.to_i
        end

      end
    end
  end
end

Version data entries

83 entries across 83 versions & 7 rubygems

Version Path
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/terminal.rb