-
Notifications
You must be signed in to change notification settings - Fork 4
/
09-simple_colors.rb
42 lines (31 loc) · 999 Bytes
/
09-simple_colors.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
require 'rubygems'
require 'ncurses'
def print_centered(string, options={})
window = options.fetch(:window, Ncurses.stdscr)
startx = options.fetch(:startx, Ncurses.getcurx(window))
starty = options.fetch(:starty, Ncurses.getcury(window))
width = options.fetch(:width, Ncurses.getmaxx(window))
startx = startx + (width - string.length) / 2
Ncurses.mvwprintw(window, starty, startx, string)
Ncurses.refresh
end
begin
Ncurses.initscr
unless Ncurses.has_colors?
Ncurses.endwin
puts "Your terminal does not support color"
exit 1
end
Ncurses.start_color
Ncurses.init_pair(1, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK)
Ncurses.attron(Ncurses.COLOR_PAIR(1))
print_centered "Viola!!! In color ...", :starty => Ncurses.getmaxy(Ncurses.stdscr)/2
Ncurses.attroff(Ncurses.COLOR_PAIR(1))
Ncurses.getch
rescue Exception => e
Ncurses.printw e.inspect + "\n"
Ncurses.printw e.backtrace.join("\n")
Ncurses.getch
ensure
Ncurses.endwin
end