Module: RTUI::TTY

Defined in:
lib/rtui/tty.rb

Class Method Summary collapse

Class Method Details

.default_widthObject



20
21
22
23
24
25
26
27
# File 'lib/rtui/tty.rb', line 20

def default_width
  stty = `stty size`
  if stty =~ /^\d+ \d+/
    stty.split[1].to_i
  else
    80
  end
end

.get_widthObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rtui/tty.rb', line 4

def get_width
  # FIXME: I don't know how portable it is. Works Linux/OSX.
  begin
    tiocgwinsz = 0x5413
    data = [0, 0, 0, 0].pack("SSSS")
    if @out.ioctl(tiocgwinsz, data) >= 0 then
      rows, cols, xpixels, ypixels = data.unpack("SSSS")
      if cols >= 0 then cols else default_width end
    else
      default_width
    end
  rescue Exception
    default_width
  end
end