-
Notifications
You must be signed in to change notification settings - Fork 0
/
ncurses_app.rb
52 lines (43 loc) · 866 Bytes
/
ncurses_app.rb
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'window'
class NcursesApp
attr_reader :windows, :win
def initialize
Ncurses.initscr
Ncurses.noecho
Ncurses.cbreak
@win = Ncurses.stdscr
@windows = []
win.notimeout(true) # No ESC delay
Ncurses.ESCDELAY = 0 # No ESC seems not to work. Try setting constant... Does not work either...
end
def scr_size
h, w = [], []
win.getmaxyx(h, w)
{ :height => h[0],
:width => w[0] }
end
def add_window(window)
windows << window
end
def run
Ncurses.refresh
run = true
while(run)
windows.each { |w| w.render }
c = win.wgetch
case c
when 27, 'q'[0] # ESC
run = false
when Ncurses::KEY_RESIZE
resize
else
yield c
end
end
end
def self.close
Ncurses.clear
Ncurses.refresh
Ncurses.endwin
end
end