forked from kristopolous/curses_text
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
137 lines (118 loc) · 2.66 KB
/
test.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <locale>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "ctext.h"
int8_t my_event(ctext *context, ctext_event event)
{
/*
switch(event)
{
case CTEXT_SCROLL:
printf("< Scroll >");
break;
case CTEXT_CLEAR:
printf("< Clear >");
break;
case CTEXT_DATA:
printf("< Data >");
break;
}
*/
return 0;
}
int main(int argc, char **argv ){
int speed = 450000;
int16_t x = 0;
int amount = 0;
locale::global(locale("en_US.utf8"));
initscr();
cbreak();
curs_set(0);
WINDOW *local_win;
ctext_config config;
local_win = newwin(9, 100, 5, 5);
start_color();
ctext ct(local_win);
// get the default config
ct.get_config(&config);
// add my handler
config.m_on_event = my_event;
//config.m_bounding_box = true;
config.m_buffer_size = 100;
config.m_scroll_on_append = true;
//config.m_do_wrap = true;
//config.m_append_top = true;
// set the config back
ct.set_config(&config);
attr_t attrs; short color_pair_number;
for(x = 0; x < 200; x++)
{
init_pair(x, x, 0);
/*
wattr_on(local_win, COLOR_PAIR(x), 0);
wattr_get(local_win, &attrs, &color_pair_number, 0);
//printf("%x %x ", attrs,color_pair_number);
wattr_off(local_win, COLOR_PAIR(x), 0);
//wattr_on(local_win, COLOR_PAIR(x), 0);
wattr_on(local_win, COLOR_PAIR(color_pair_number), 0);
wattr_get(local_win, &attrs, &color_pair_number, 0);
printf("%x %x\r\n", attrs,color_pair_number);
wattr_off(local_win, COLOR_PAIR(x), 0);
mvwaddwstr(local_win, 0, x, L"h");
wattr_off(local_win, COLOR_PAIR(x), 0);
wrefresh(local_win);
usleep(speed / 200);
*/
}
char buffer[32], *ptr;
int color = 0, round;
for(x = 0; x < 15; x++) {
for(round = 0; round < 9; round++)
{
wattr_on(local_win, COLOR_PAIR(color % 200), 0);
ct.printf("%c", (color % 26) + 'A' );
wattr_off(local_win, COLOR_PAIR(color % 200), 0);
color++;
}
wattr_on(local_win, COLOR_PAIR(x * 3 + 1), 0);
ct.printf("%c%c%c\n", x + 'A', x + 'A', x + 'A');
wattr_off(local_win, COLOR_PAIR(x * 3 + 1), 0);
//usleep(speed / 15);
/*
for(ptr = buffer; *ptr; ptr++) {
ct.putchar((char)*ptr);
usleep(speed / 15);
}
*/
usleep(speed / 10);
}
/*
for(x = 0; x < 10; x++) {
ct.right();
ct.down();
usleep(speed);
}
*/
for(x = 0; x < 20; x++) {
ct.left();
ct.up();
usleep(speed);
}
/*
for(x = 0; x < 18; x++) {
amount = ct.clear(1);
if(x < 15)
{
assert(amount == 1);
}
else
{
assert(amount == 0);
}
usleep(speed);
}
*/
endwin();
return 0;
}