Class: Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/mdisc/screen.rb

Overview

The curses library only provides limit functions. Thus we need to add more wrapper functions based on curses.

Instance Method Summary collapse

Constructor Details

#initialize(height = 25, width = 80) ⇒ Screen

Returns a new instance of Screen.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mdisc/screen.rb', line 7

def initialize(height = 25, width = 80)
  Curses.init_screen
  Curses.start_color
  Curses.cbreak
  Curses.stdscr.keypad(true)
  Curses.init_pair(1, Curses::COLOR_BLUE, Curses::COLOR_BLACK)
  Curses.init_pair(2, Curses::COLOR_CYAN, Curses::COLOR_BLACK)
  Curses.init_pair(3, Curses::COLOR_RED, Curses::COLOR_BLACK)
  Curses.init_pair(4, Curses::COLOR_MAGENTA, Curses::COLOR_BLACK)
  # height, width, top, left
  @draw = Curses::Window.new(height, width, 0, 0)
end

Instance Method Details

#clear(top, bottom) ⇒ Object



28
29
30
31
32
33
# File 'lib/mdisc/screen.rb', line 28

def clear(top, bottom)
  (top..bottom).each do |i|
    @draw.setpos(i, 0)
    @draw.clrtoeol
  end
end

#getchObject



39
40
41
# File 'lib/mdisc/screen.rb', line 39

def getch
  @draw.getch
end

#getstrObject



43
44
45
# File 'lib/mdisc/screen.rb', line 43

def getstr
  @draw.getstr
end

#line(y, x, string, num = 0) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/mdisc/screen.rb', line 20

def line(y, x, string, num = 0)
  color = Curses.color_pair num
  @draw.setpos(y, x)
  @draw.clrtoeol
  @draw.attrset color
  @draw.addstr(strip_invalid(string))
end

#refreshObject



35
36
37
# File 'lib/mdisc/screen.rb', line 35

def refresh
  @draw.refresh
end

#setpos(*args) ⇒ Object



47
48
49
# File 'lib/mdisc/screen.rb', line 47

def setpos(*args)
  @draw.setpos *args
end