summaryrefslogtreecommitdiff
path: root/lib/highline/terminal/ncurses.rb
blob: cb2b593dd9da0fb07548f5a61bfefe2c71895a40 (plain)
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
# coding: utf-8

class HighLine
  module SystemExtensions
    module NCurses
      require 'ffi-ncurses'
      CHARACTER_MODE = "ncurses"    # For Debugging purposes only.

      def raw_no_echo_mode
        FFI::NCurses.initscr
        FFI::NCurses.cbreak
      end

      def restore_mode
        FFI::NCurses.endwin
      end

      #
      # A ncurses savvy method to fetch the console columns, and rows.
      #
      def terminal_size
        size = [80, 40]
        FFI::NCurses.initscr
        begin
          size = FFI::NCurses.getmaxyx(FFI::NCurses.stdscr).reverse
        ensure
          FFI::NCurses.endwin
        end
        size
      end
    end
  end
end