-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.vala
82 lines (67 loc) · 1.4 KB
/
colors.vala
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Curses;
using Posix;
public class Demo {
public MainLoop loop;
private IOChannel io_channel;
internal IOSource io;
public Demo() {
loop = new MainLoop();
io_channel = new IOChannel.unix_new(Posix.STDIN_FILENO);
io = new IOSource(io_channel, IOCondition.IN);
io.attach(loop.get_context());
}
public void start() {
initscr();
if (has_colors() == false) {
endwin();
printf("Your terminal does not support color\n");
exit(EXIT_FAILURE);
}
start_color();
noecho();
stdscr.keypad(true);
}
public void stop() {
endwin();
}
public void activate() {
for (short c = 0; c < 256; c++) {
init_pair(c, c, Color.BLACK);
}
io.set_callback(() => {
getch();
return Source.CONTINUE;
});
}
public void paint() {
short c = 0;
for (int y = 0; y < LINES-1; y++) {
for (int x = 0; x < COLS; x++) {
if (c > 255) {
c = 0;
}
attron(COLOR_PAIR(c));
mvprintw(y, x, "+");
attroff(COLOR_PAIR(c));
c++;
}
}
mvprintw(LINES-1, 0, "COLORS=%i", COLORS);
}
public void run() {
loop.run();
}
public void redraw() {
refresh();
}
static int main(string[] args) {
var app = new Demo();
app.start();
app.activate();
app.paint();
app.redraw();
app.run();
app.stop();
return EXIT_SUCCESS;
}
}