Sha256: c18a33cab96d71d083346c956d3e14f3e6105cec053dc05ffead66c48c0644e3

Contents?: true

Size: 580 Bytes

Versions: 2

Compression:

Stored size: 580 Bytes

Contents

module SqlTracker
  class Terminal
    DEFAULT_WIDTH = 80
    MIN_WIDTH = 10

    def self.width
      if unix?
        result = (dynamic_width_stty.nonzero? || dynamic_width_tput)
        result < MIN_WIDTH ? DEFAULT_WIDTH : result
      else
        DEFAULT_WIDTH
      end
    end

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sql_tracker-1.3.2 lib/sql_tracker/terminal.rb
sql_tracker-1.3.1 lib/sql_tracker/terminal.rb