-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathoutput.cpp
789 lines (742 loc) · 17.8 KB
/
output.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
#if (defined _WIN32 || defined WINDOWS)
#include "catacurse.h"
#else
#include <curses.h>
#endif
#include <string>
#include <vector>
#include <cstdarg>
#include <cstring>
#include <stdlib.h>
#include "color.h"
#include "output.h"
#include "rng.h"
#include "keypress.h"
#include "options.h"
#define LINE_XOXO 4194424
#define LINE_OXOX 4194417
#define LINE_XXOO 4194413
#define LINE_OXXO 4194412
#define LINE_OOXX 4194411
#define LINE_XOOX 4194410
#define LINE_XXXO 4194420
#define LINE_XXOX 4194422
#define LINE_XOXX 4194421
#define LINE_OXXX 4194423
#define LINE_XXXX 4194414
nc_color hilite(nc_color c)
{
switch (c) {
case c_white: return h_white;
case c_ltgray: return h_ltgray;
case c_dkgray: return h_dkgray;
case c_red: return h_red;
case c_green: return h_green;
case c_blue: return h_blue;
case c_cyan: return h_cyan;
case c_magenta: return h_magenta;
case c_brown: return h_brown;
case c_ltred: return h_ltred;
case c_ltgreen: return h_ltgreen;
case c_ltblue: return h_ltblue;
case c_ltcyan: return h_ltcyan;
case c_pink: return h_pink;
case c_yellow: return h_yellow;
}
return h_white;
}
nc_color invert_color(nc_color c)
{
if (OPTIONS[OPT_NO_CBLINK]) {
switch (c) {
case c_white:
case c_ltgray:
case c_dkgray: return i_ltgray;
case c_red:
case c_ltred: return i_red;
case c_green:
case c_ltgreen: return i_green;
case c_blue:
case c_ltblue: return i_blue;
case c_cyan:
case c_ltcyan: return i_cyan;
case c_magenta:
case c_pink: return i_magenta;
case c_brown:
case c_yellow: return i_brown;
}
}
switch (c) {
case c_white: return i_white;
case c_ltgray: return i_ltgray;
case c_dkgray: return i_dkgray;
case c_red: return i_red;
case c_green: return i_green;
case c_blue: return i_blue;
case c_cyan: return i_cyan;
case c_magenta: return i_magenta;
case c_brown: return i_brown;
case c_yellow: return i_yellow;
case c_ltred: return i_ltred;
case c_ltgreen: return i_ltgreen;
case c_ltblue: return i_ltblue;
case c_ltcyan: return i_ltcyan;
case c_pink: return i_pink;
}
}
nc_color red_background(nc_color c)
{
switch (c) {
case c_white: return c_white_red;
case c_ltgray: return c_ltgray_red;
case c_dkgray: return c_dkgray_red;
case c_red: return c_red_red;
case c_green: return c_green_red;
case c_blue: return c_blue_red;
case c_cyan: return c_cyan_red;
case c_magenta: return c_magenta_red;
case c_brown: return c_brown_red;
case c_ltred: return c_ltred_red;
case c_ltgreen: return c_ltgreen_red;
case c_ltblue: return c_ltblue_red;
case c_ltcyan: return c_ltcyan_red;
case c_pink: return c_pink_red;
case c_yellow: return c_yellow_red;
}
return c_white_red;
}
nc_color rand_color()
{
switch (rng(0, 9)) {
case 0: return c_white;
case 1: return c_ltgray;
case 2: return c_green;
case 3: return c_red;
case 4: return c_yellow;
case 5: return c_blue;
case 6: return c_ltblue;
case 7: return c_pink;
case 8: return c_magenta;
case 9: return c_brown;
}
return c_dkgray;
}
void mvputch(int y, int x, nc_color FG, long ch)
{
attron(FG);
mvaddch(y, x, ch);
attroff(FG);
}
void wputch(WINDOW* w, nc_color FG, long ch)
{
wattron(w, FG);
waddch(w, ch);
wattroff(w, FG);
}
void mvwputch(WINDOW *w, int y, int x, nc_color FG, long ch)
{
wattron(w, FG);
mvwaddch(w, y, x, ch);
wattroff(w, FG);
}
void mvputch_inv(int y, int x, nc_color FG, long ch)
{
nc_color HC = invert_color(FG);
attron(HC);
mvaddch(y, x, ch);
attroff(HC);
}
void mvwputch_inv(WINDOW* w, int y, int x, nc_color FG, long ch)
{
nc_color HC = invert_color(FG);
wattron(w, HC);
mvwaddch(w, y, x, ch);
wattroff(w, HC);
}
void mvputch_hi(int y, int x, nc_color FG, long ch)
{
nc_color HC = hilite(FG);
attron(HC);
mvaddch(y, x, ch);
attroff(HC);
}
void mvwputch_hi(WINDOW* w, int y, int x, nc_color FG, long ch)
{
nc_color HC = hilite(FG);
wattron(w, HC);
mvwaddch(w, y, x, ch);
wattroff(w, HC);
}
void mvprintz(int y, int x, nc_color FG, const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[6000];
vsprintf(buff, mes, ap);
va_end(ap);
attron(FG);
mvprintw(y, x, buff);
attroff(FG);
}
void mvwprintz(WINDOW* w, int y, int x, nc_color FG, const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
// char buff[4096];
// vsprintf(buff, mes, ap);
char buff[6000];
vsprintf(buff, mes, ap);
wattron(w, FG);
// wmove(w, y, x);
mvwprintw(w, y, x, buff);
wattroff(w, FG);
va_end(ap);
}
void printz(nc_color FG, const char *mes, ...)
{
va_list ap;
va_start(ap,mes);
char buff[6000];
vsprintf(buff, mes, ap);
va_end(ap);
attron(FG);
printw(buff);
attroff(FG);
}
void wprintz(WINDOW *w, nc_color FG, const char *mes, ...)
{
va_list ap;
va_start(ap,mes);
char buff[6000];
vsprintf(buff, mes, ap);
va_end(ap);
wattron(w, FG);
wprintw(w, buff);
wattroff(w, FG);
}
void draw_tabs(WINDOW *w, int active_tab, ...)
{
int win_width;
win_width = getmaxx(w);
std::vector<std::string> labels;
va_list ap;
va_start(ap, active_tab);
char *tmp;
while (tmp = va_arg(ap, char *))
labels.push_back((std::string)(tmp));
va_end(ap);
// Draw the line under the tabs
for (int x = 0; x < win_width; x++)
mvwputch(w, 2, x, c_white, LINE_OXOX);
int total_width = 0;
for (int i = 0; i < labels.size(); i++)
total_width += labels[i].length() + 6; // "< |four| >"
if (total_width > win_width) {
//debugmsg("draw_tabs not given enough space! %s", labels[0]);
return;
}
// Extra "buffer" space per each side of each tab
double buffer_extra = (win_width - total_width) / (labels.size() * 2);
int buffer = int(buffer_extra);
// Set buffer_extra to (0, 1); the "extra" whitespace that builds up
buffer_extra = buffer_extra - buffer;
int xpos = 0;
double savings = 0;
for (int i = 0; i < labels.size(); i++) {
int length = labels[i].length();
xpos += buffer + 2;
savings += buffer_extra;
if (savings > 1) {
savings--;
xpos++;
}
mvwputch(w, 0, xpos, c_white, LINE_OXXO);
mvwputch(w, 1, xpos, c_white, LINE_XOXO);
mvwputch(w, 0, xpos + length + 1, c_white, LINE_OOXX);
mvwputch(w, 1, xpos + length + 1, c_white, LINE_XOXO);
if (i == active_tab) {
mvwputch(w, 1, xpos - 2, h_white, '<');
mvwputch(w, 1, xpos + length + 3, h_white, '>');
mvwputch(w, 2, xpos, c_white, LINE_XOOX);
mvwputch(w, 2, xpos + length + 1, c_white, LINE_XXOO);
mvwprintz(w, 1, xpos + 1, h_white, labels[i].c_str());
for (int x = xpos + 1; x <= xpos + length; x++) {
mvwputch(w, 0, x, c_white, LINE_OXOX);
mvwputch(w, 2, x, c_black, 'x');
}
} else {
mvwputch(w, 2, xpos, c_white, LINE_XXOX);
mvwputch(w, 2, xpos + length + 1, c_white, LINE_XXOX);
mvwprintz(w, 1, xpos + 1, c_white, labels[i].c_str());
for (int x = xpos + 1; x <= xpos + length; x++)
mvwputch(w, 0, x, c_white, LINE_OXOX);
}
xpos += length + 1 + buffer;
}
}
void debugmsg(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
attron(c_red);
mvprintw(0, 0, "DEBUG: %s \n Press spacebar...", buff);
while(getch() != ' ');
attroff(c_red);
}
bool query_yn(const char *mes, ...)
{
bool force_uc = OPTIONS[OPT_FORCE_YN];
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
int win_width = strlen(buff) + 26;
WINDOW* w = newwin(3, win_width, 11, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w, 1, 1, c_ltred, "%s (%s)", buff,
(force_uc ? "Y/N - Case Sensitive" : "y/n"));
wrefresh(w);
char ch;
do
ch = getch();
while (ch != 'Y' && ch != 'N' && (force_uc || (ch != 'y' && ch != 'n')));
werase(w);
wrefresh(w);
delwin(w);
refresh();
if (ch == 'Y' || ch == 'y')
return true;
return false;
}
int query_int(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
int win_width = strlen(buff) + 10;
WINDOW* w = newwin(3, win_width, 11, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w, 1, 1, c_ltred, "%s (0-9)", buff);
wrefresh(w);
int temp;
do
temp = getch();
while ((temp-48)<0 || (temp-48)>9);
werase(w);
wrefresh(w);
delwin(w);
refresh();
return temp-48;
}
std::string string_input_popup(const char *mes, ...)
{
std::string ret;
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
int startx = strlen(buff) + 2;
WINDOW* w = newwin(3, 80, 11, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w, 1, 1, c_ltred, "%s", buff);
for (int i = startx + 1; i < 79; i++)
mvwputch(w, 1, i, c_ltgray, '_');
int posx = startx;
mvwputch(w, 1, posx, h_ltgray, '_');
do {
wrefresh(w);
long ch = getch();
if (ch == 27) { // Escape
werase(w);
wrefresh(w);
delwin(w);
refresh();
return "";
} else if (ch == '\n') {
werase(w);
wrefresh(w);
delwin(w);
refresh();
return ret;
} else if ((ch == KEY_BACKSPACE || ch == 127) && posx > startx) {
// Move the cursor back and re-draw it
ret = ret.substr(0, ret.size() - 1);
mvwputch(w, 1, posx, c_ltgray, '_');
posx--;
mvwputch(w, 1, posx, h_ltgray, '_');
} else {
ret += ch;
mvwputch(w, 1, posx, c_magenta, ch);
posx++;
mvwputch(w, 1, posx, h_ltgray, '_');
}
} while (true);
}
std::string string_input_popup(int max_length, const char *mes, ...)
{
std::string ret;
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
int startx = strlen(buff) + 2;
WINDOW* w = newwin(3, 80, 11, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w, 1, 1, c_ltred, "%s", buff);
for (int i = startx + 1; i < 79; i++)
mvwputch(w, 1, i, c_ltgray, '_');
int posx = startx;
mvwputch(w, 1, posx, h_ltgray, '_');
do {
wrefresh(w);
long ch = getch();
if (ch == 27) { // Escape
werase(w);
wrefresh(w);
delwin(w);
refresh();
return "";
} else if (ch == '\n') {
werase(w);
wrefresh(w);
delwin(w);
refresh();
return ret;
} else if ((ch == KEY_BACKSPACE || ch == 127) && posx > startx) {
// Move the cursor back and re-draw it
ret = ret.substr(0, ret.size() - 1);
mvwputch(w, 1, posx, c_ltgray, '_');
posx--;
mvwputch(w, 1, posx, h_ltgray, '_');
} else if(ret.size() < max_length || max_length == 0) {
ret += ch;
mvwputch(w, 1, posx, c_magenta, ch);
posx++;
mvwputch(w, 1, posx, h_ltgray, '_');
}
} while (true);
}
char popup_getkey(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[8192];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
int width = 0;
int height = 2;
size_t pos = tmp.find_first_of('\n');
while (pos != std::string::npos) {
height++;
if (pos > width)
width = pos;
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
if (width == 0 || tmp.length() > width)
width = tmp.length();
width += 2;
if (height > 25)
height = 25;
WINDOW* w = newwin(height + 1, width, int((25 - height) / 2),
int((80 - width) / 2));
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
tmp = buff;
pos = tmp.find_first_of('\n');
int line_num = 0;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
mvwprintz(w, line_num, 1, c_white, line.c_str());
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());
wrefresh(w);
char ch = getch();;
werase(w);
wrefresh(w);
delwin(w);
refresh();
return ch;
}
int menu_vec(const char *mes, std::vector<std::string> options)
{
if (options.size() == 0) {
debugmsg("0-length menu (\"%s\")", mes);
return -1;
}
std::string title = mes;
int height = 3 + options.size(), width = title.length() + 2;
for (int i = 0; i < options.size(); i++) {
if (options[i].length() + 6 > width)
width = options[i].length() + 6;
}
WINDOW* w = newwin(height, width, 1, 10);
wattron(w, c_white);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintw(w, 1, 1, title.c_str());
for (int i = 0; i < options.size(); i++)
mvwprintw(w, i + 2, 1, "%c: %s", (i < 9? i + '1' :
(i == 9? '0' : 'a' + i - 10)),
options[i].c_str());
long ch;
wrefresh(w);
int res;
do
{
ch = getch();
if (ch >= '1' && ch <= '9')
res = ch - '1' + 1;
else
if (ch == '0')
res = 10;
else
if (ch >= 'a' && ch <= 'z')
res = ch - 'a' + 11;
else
res = -1;
if (res > options.size())
res = -1;
}
while (res == -1);
werase(w);
wrefresh(w);
delwin(w);
return (res);
}
int menu(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char* tmp;
std::vector<std::string> options;
bool done = false;
while (!done) {
tmp = va_arg(ap, char*);
if (tmp != NULL) {
std::string strtmp = tmp;
options.push_back(strtmp);
} else
done = true;
}
return (menu_vec(mes, options));
}
void popup_top(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
int width = 0;
int height = 2;
size_t pos = tmp.find_first_of('\n');
while (pos != std::string::npos) {
height++;
if (pos > width)
width = pos;
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
if (width == 0 || tmp.length() > width)
width = tmp.length();
width += 2;
WINDOW* w = newwin(height + 1, width, 0, int((80 - width) / 2));
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
tmp = buff;
pos = tmp.find_first_of('\n');
int line_num = 0;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
mvwprintz(w, line_num, 1, c_white, line.c_str());
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());
wrefresh(w);
char ch;
do
ch = getch();
while(ch != ' ' && ch != '\n' && ch != KEY_ESCAPE);
werase(w);
wrefresh(w);
delwin(w);
refresh();
}
void popup(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[8192];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
int width = 0;
int height = 2;
size_t pos = tmp.find_first_of('\n');
while (pos != std::string::npos) {
height++;
if (pos > width)
width = pos;
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
if (width == 0 || tmp.length() > width)
width = tmp.length();
width += 2;
if (height > 25)
height = 25;
WINDOW* w = newwin(height + 1, width, int((25 - height) / 2),
int((80 - width) / 2));
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
tmp = buff;
pos = tmp.find_first_of('\n');
int line_num = 0;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
mvwprintz(w, line_num, 1, c_white, line.c_str());
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());
wrefresh(w);
char ch;
do
ch = getch();
while(ch != ' ' && ch != '\n' && ch != KEY_ESCAPE);
werase(w);
wrefresh(w);
delwin(w);
refresh();
}
void popup_nowait(const char *mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[8192];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
int width = 0;
int height = 2;
size_t pos = tmp.find_first_of('\n');
while (pos != std::string::npos) {
height++;
if (pos > width)
width = pos;
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
if (width == 0 || tmp.length() > width)
width = tmp.length();
width += 2;
if (height > 25)
height = 25;
WINDOW* w = newwin(height + 1, width, int((25 - height) / 2),
int((80 - width) / 2));
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
tmp = buff;
pos = tmp.find_first_of('\n');
int line_num = 0;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
mvwprintz(w, line_num, 1, c_white, line.c_str());
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());
wrefresh(w);
delwin(w);
refresh();
}
void full_screen_popup(const char* mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[8192];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
WINDOW* w = newwin(25, 80, 0, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
size_t pos = tmp.find_first_of('\n');
int line_num = 0;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
mvwprintz(w, line_num, 1, c_white, line.c_str());
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 1, c_white, tmp.c_str());
wrefresh(w);
char ch;
do
ch = getch();
while(ch != ' ' && ch != '\n' && ch != KEY_ESCAPE);
werase(w);
wrefresh(w);
delwin(w);
refresh();
}
char rand_char()
{
switch (rng(0, 9)) {
case 0: return '|';
case 1: return '-';
case 2: return '#';
case 3: return '?';
case 4: return '&';
case 5: return '.';
case 6: return '%';
case 7: return '{';
case 8: return '*';
case 9: return '^';
}
return '?';
}
// this translates symbol y, u, n, b to NW, NE, SE, SW lines correspondingly
// h, j, c to horizontal, vertical, cross correspondingly
long special_symbol (char sym)
{
switch (sym)
{
case 'j': return LINE_XOXO;
case 'h': return LINE_OXOX;
case 'c': return LINE_XXXX;
case 'y': return LINE_OXXO;
case 'u': return LINE_OOXX;
case 'n': return LINE_XOOX;
case 'b': return LINE_XXOO;
default: return sym;
}
}