class Engine

The main interface with Curses.

This acts as a middleman, abstracting away Curses' details.

Constants

Colors

All possible colors.

Public Class Methods

new(min_width=nil, min_height=nil) click to toggle source

Initializes Ncurses with minimal width and height.

# File lib/tabscroll/engine.rb, line 23
def initialize(min_width=nil, min_height=nil)
  @has_colors = nil

  @screen = Curses::init_screen
  return nil if not @screen

  if min_width and min_height
    cur_width  = @screen.maxx
    cur_height = @screen.maxy

    if cur_width < @width or cur_height < @height
      self.exit
      $stderr << "Error: Screen size too small (#{cur_width}x#{cur_height})\n"
      $stderr << "Please resize your terminal to at least #{@width}x#{@height}\n"
      return nil
    end
  end

  @has_colors = Curses.has_colors?
  if @has_colors
    Curses.start_color
    Curses.use_default_colors # will use default background

    # Initializes:   constant          foreground             bg
    Curses.init_pair(Colors[:white],   Curses::COLOR_BLACK,   -1)
    Curses.init_pair(Colors[:blue],    Curses::COLOR_BLUE,    -1)
    Curses.init_pair(Colors[:red],     Curses::COLOR_RED,     -1)
    Curses.init_pair(Colors[:green],   Curses::COLOR_GREEN,   -1)
    Curses.init_pair(Colors[:magenta], Curses::COLOR_MAGENTA, -1)
    Curses.init_pair(Colors[:yellow],  Curses::COLOR_YELLOW,  -1)
    Curses.init_pair(Colors[:cyan],    Curses::COLOR_CYAN,    -1)
  end

  Curses::cbreak
  Curses::curs_set 0
  Curses::noecho
  Curses::nonl
  Curses::stdscr.keypad = true # extra keys
end

Public Instance Methods

exit() click to toggle source
# File lib/tabscroll/engine.rb, line 71
def exit
  Curses::refresh
  Curses::close_screen
end
getchar() click to toggle source
# File lib/tabscroll/engine.rb, line 85
def getchar
  return Curses::getch
end
height() click to toggle source
# File lib/tabscroll/engine.rb, line 67
def height
  return Curses::lines
end
set_color(color) click to toggle source
# File lib/tabscroll/engine.rb, line 76
def set_color color
  if @has_colors
    @screen.attron Curses::color_pair(color)
    return self
  else
    return nil
  end
end
timeout(timeout) click to toggle source

timeout says how many milliseconds we wait for a key to be pressed.

# File lib/tabscroll/engine.rb, line 91
def timeout timeout
  Curses::timeout = timeout
end
width() click to toggle source
# File lib/tabscroll/engine.rb, line 63
def width
  return Curses::cols
end