Class: Screen
- Inherits:
-
Object
- Object
- Screen
- 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
- #clear(top, bottom) ⇒ Object
- #getch ⇒ Object
- #getstr ⇒ Object
-
#initialize(height = 25, width = 80) ⇒ Screen
constructor
A new instance of Screen.
- #line(y, x, string, num = 0) ⇒ Object
- #refresh ⇒ Object
- #setpos(*args) ⇒ Object
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 |
#getch ⇒ Object
39 40 41 |
# File 'lib/mdisc/screen.rb', line 39 def getch @draw.getch end |
#getstr ⇒ Object
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 |
#refresh ⇒ Object
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 |