Class: SqlTracker::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_tracker/terminal.rb

Constant Summary collapse

DEFAULT_WIDTH =
80
MIN_WIDTH =
10

Class Method Summary collapse

Class Method Details

.dynamic_width_sttyObject



15
16
17
# File 'lib/sql_tracker/terminal.rb', line 15

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

.dynamic_width_tputObject



19
20
21
# File 'lib/sql_tracker/terminal.rb', line 19

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

.unix?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/sql_tracker/terminal.rb', line 23

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

.widthObject



6
7
8
9
10
11
12
13
# File 'lib/sql_tracker/terminal.rb', line 6

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