8 ## maps the key numbers you get from the Ncurses module to strings
13 when ?\n.ord, Ncurses::KEY_ENTER
15 when ?\b.ord, Ncurses::KEY_BACKSPACE, 127
21 when Ncurses::KEY_HOME
23 when Ncurses::KEY_RIGHT
25 when Ncurses::KEY_LEFT
29 when Ncurses::KEY_DOWN
33 ## keep spaces as they are, makes more sense
36 when Ncurses::KEY_BTAB
40 when 1..26 # CTRL + ...
47 logerr("key not found: #{key}")
54 ## Initialize nourses. This needs to be called once, even after using closei
56 @@window = Ncurses.initscr
60 ## (Re)Start the ncurses
63 @@screen = Ncurses.stdscr
66 Ncurses.use_default_colors
71 Ncurses.halfdelay(200)
85 Ncurses.curs_set(bool ? 1 : 0)
92 def running?() @@running end
94 ## Clears the whole screen by writing lines * cols spaces at position (0, 0).
95 ## I doubt that this is the best way of doing so, but this is rarely used so i don't care.
97 Ncurses.mvaddstr(0, 0, ' ' * (lines * cols))
101 CLI.keytable(Ncurses.getch)
105 print "\e]2;#{x}\007"
124 Ncurses.addstr(args[0].to_s)
126 if (y = args[0]) < 0 then y += Ncurses.LINES end
127 Ncurses.mvaddstr(y, 0, args[1].to_s)
129 if (y = args[0]) < 0 then y += Ncurses.LINES end
130 if (x = args[1]) < 0 then x += Ncurses.COLS end
131 Ncurses.mvaddstr(y, x, args[2].to_s)
135 def color(fg = -1, bg = -1)
137 Ncurses.color_set(get_color(fg,bg), nil)
141 def attr_set(fg, bg, attr=nil)
144 Ncurses.attrset(attr | Ncurses::COLOR_PAIR(get_color(fg, bg)))
146 Ncurses.color_set(get_color(fg, bg), nil)
149 Ncurses.attrset(attr)
153 def attr_at(x, y, len, fg, bg, attr=0)
155 Ncurses.mvchgat(y, x, len, attr, get_color(fg, bg), nil)
158 def color_at y, x=0, len=-1, fg=-1, bg=-1, attributes=0
159 fg, bg = -1, -1 unless Opt.color
160 if y < 0 then y += Ncurses.LINES end
161 Ncurses.mvchgat(y, x, len, attributes, get_color(fg, bg), nil)
164 def color_bold_at y, x=0, len=-1, fg=-1, bg=-1
165 fg, bg = -1, -1 unless Opt.color
166 color_at(y, x, len, fg, bg, attributes = Ncurses::A_BOLD)
169 def color_reverse_bold_at y, x=0, len=-1, fg=-1, bg=-1
171 color_at(y, x, len, fg, bg, Ncurses::A_REVERSE | Ncurses::A_BOLD)
173 Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE | Ncurses::A_BOLD, 0, nil)
176 alias color_bold_reverse_at color_reverse_bold_at
178 def color_reverse_at y, x=0, len=-1, fg=-1, bg=-1
180 color_at(y, x, len, fg, bg, Ncurses::A_REVERSE)
182 Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, 0, nil)
186 def get_color(fg, bg)
188 color = @@colortable[n]
191 size = @@colortable.reject{|x| x.nil? }.size + 1
192 Ncurses::init_pair(size, fg, bg)
193 color = @@colortable[n] = size
200 Ncurses.attron(Ncurses::A_BOLD)
202 Ncurses.attroff(Ncurses::A_BOLD)
206 def reverse(b = true)
208 Ncurses.attron(Ncurses::A_REVERSE)
210 Ncurses.attroff(Ncurses::A_REVERSE)