class Screen

A segment of the terminal screen.

BUG WARNING HACK FUCK Whenever I use @win.attrset/@win.setpos/@win.addch it doesn't work at all. Apparently, when I do this, Curses::getch clears up the entire screen.

DO NOT DO THIS

Attributes

height[R]
width[R]

Public Class Methods

new(x, y, w, h) click to toggle source

Creates a Screen at `x` `y` `w` `h`.

# File lib/tabscroll/screen.rb, line 18
def initialize(x, y, w, h)
  @win = Curses::Window.new(h, w, y, x)
  @width  = w
  @height = h
end

Public Instance Methods

background(char) click to toggle source
# File lib/tabscroll/screen.rb, line 108
def background char
  @win.bkgd char
  @win.refresh
end
box(horizontal=0, vertical=0) click to toggle source

Sets the Screen border.

  • If all arguments are set, that's ok.

  • If only the first 2 arguments are set, they are the vertical and horizontal chars.

# File lib/tabscroll/screen.rb, line 119
def box(horizontal=0, vertical=0)
  @win.box(horizontal, vertical)
  @win.refresh
end
clear() click to toggle source

Erases all of the Screen's contents

# File lib/tabscroll/screen.rb, line 77
def clear
  @win.clear
end
move(x, y) click to toggle source

Moves window so that the upper-left corner is at `x` `y`.

# File lib/tabscroll/screen.rb, line 87
def move(x, y)
  @win.move(y, x)
end
mvaddch(x, y, c, color=nil) click to toggle source

Puts a character c on (x, y) with optional color.

# File lib/tabscroll/screen.rb, line 38
def mvaddch(x, y, c, color=nil)
  return if x < 0 or x >= @width
  return if y < 0 or y >= @height

  self.with_color color do
    Curses::setpos(@win.begy + y, @win.begx + x)
    Curses::addch c
  end
end
mvaddstr(x, y, str, color=nil) click to toggle source

Puts a string str on (x, y) with optional color.

# File lib/tabscroll/screen.rb, line 49
  def mvaddstr(x, y, str, color=nil)
    return if x < 0 or x >= @width
    return if y < 0 or y >= @height

    self.with_color color do
#      @win.setpos(@win.begy + y, @win.begx + x)
#      @win.addstr str
      Curses::setpos(@win.begy + y, @win.begx + x)
      Curses::addstr str
    end
  end
mvaddstr_center(y, str, color=nil) click to toggle source

Puts a string str centered on y with optional color.

# File lib/tabscroll/screen.rb, line 62
def mvaddstr_center(y, str, color=nil)
  x = (@width/2) - (str.length/2)
  self.mvaddstr(x, y, str, color)
end
mvaddstr_left(y, str, color=nil) click to toggle source
# File lib/tabscroll/screen.rb, line 67
def mvaddstr_left(y, str, color=nil)
  self.mvaddstr(0, y, str, color)
end
mvaddstr_right(y, str, color=nil) click to toggle source
# File lib/tabscroll/screen.rb, line 71
def mvaddstr_right(y, str, color=nil)
  x = @width - str.length
  self.mvaddstr(x, y, str, color)
end
refresh() click to toggle source

Commits the changes on the Screen.

# File lib/tabscroll/screen.rb, line 82
def refresh
  @win.refresh
end
resize(w, h) click to toggle source

Resizes window to width and +h+eight.

# File lib/tabscroll/screen.rb, line 92
def resize(w, h)
  @win.resize(h, w)
  @width  = w
  @height = h
end
set_color(color) click to toggle source

Sets the current color of the Screen.

# File lib/tabscroll/screen.rb, line 25
def set_color color
  Curses::attrset(Curses::color_pair color)
end
timeout(delay=-1) click to toggle source

Set block/nonblocking reads for window.

  • If `delay` is negative, blocking read is used.

  • If `delay` is zero, nonblocking read is used.

  • If `delay` is positive, waits for `delay` milliseconds and returns ERR of no input.

# File lib/tabscroll/screen.rb, line 104
def timeout(delay=-1)
  @win.timeout = delay
end
with_color(color=nil) { || ... } click to toggle source

Executes a block of code encapsulated within a color on/off. Note that the color can be overrided.

# File lib/tabscroll/screen.rb, line 31
def with_color(color=nil)
  Curses::attron(Curses::color_pair color) if color
  yield
  Curses::attroff(Curses::color_pair color) if color
end