File: terminal.rb

package info (click to toggle)
ruby-tins 1.32.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,248 kB
  • sloc: ruby: 6,659; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 699 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
begin
  require 'io/console'
rescue LoadError
end

module Tins
  module Terminal

    module_function

    def winsize
      if IO.respond_to?(:console)
        console = IO.console
        if console.respond_to?(:winsize)
          console.winsize
        else
          []
        end
      else
        []
      end
    end

    def rows
      winsize[0] || `stty size 2>/dev/null`.split[0].to_i.nonzero? ||
        `tput lines 2>/dev/null`.to_i.nonzero? || 25
    end

    def lines
      rows
    end

    def columns
      winsize[1] || `stty size 2>/dev/null`.split[1].to_i.nonzero? ||
        `tput cols 2>/dev/null`.to_i.nonzero? || 80
    end

    def cols
      columns
    end
  end
end