-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ncurses.h
103 lines (84 loc) · 1.88 KB
/
ncurses.h
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
/* ncurses wrapper for bitbox text mode
*
* Copyright 2015, Adrien Destugues <[email protected]>
*
* This file is distributed under the terms of the MIT license.
*/
#include "lib/textmode/textmode.h"
#include "lib/events/events.h"
int X;
int Y;
extern uint8_t text_color;
enum attributes{
A_NORMAL,
A_REVERSE,
A_BOLD
};
#define LINES 30
#define COLUMNS 80
#define WHITE RGB(255,255,255)
#define BLACK RGB(0,0,0)
#define PINK RGB(200,0,200)
#define LIGHTPINK RGB(255,130,255)
#define RED RGB(255,0,0)
#define BLUE RGB(0,0,255)
#define GREEN RGB(0,255,0)
#define YELLOW RGB(255,255,0)
#define CYAN RGB(0,255,255)
static inline void initscr()
{
text_color = 0;
clear();
set_palette(A_NORMAL, WHITE,BLACK); // boring white on black
set_palette(A_REVERSE, LIGHTPINK, PINK); // light pink on pink
set_palette(A_BOLD, YELLOW, BLACK); // gold on black
set_palette(3, WHITE, PINK);
set_palette(4, WHITE, BLUE);
set_palette(5, WHITE, GREEN);
set_palette(6, WHITE, YELLOW);
set_palette(A_NORMAL | 8,WHITE, BLUE); // white on blue (cursor)
set_palette(A_REVERSE | 8,BLACK, BLUE); // black on blue (cursor)
set_palette(A_BOLD | 8,YELLOW, BLUE); // gold on blue (cursor)
}
static inline void erase()
{
clear();
}
static inline void refresh()
{
vram_attr[Y][X] |= 8;
}
static inline void mvaddstr(int y, int x, char* text)
{
int k = print_at(x, y, text_color, text);
Y = y;
X = (x + k) % 80;
}
static inline void addstr(char* text)
{
int k = print_at(X, Y, text_color, text);
X = (X + k) % 80;
}
static inline void addch(char ch)
{
vram[Y][X] = ch;
vram_attr[Y][X] = text_color;
X++;
if (X > 79) X = 0;
}
static inline void move(int y, int x)
{
X = x;
Y = y;
}
static inline void attrset(int attr)
{
text_color = attr;
};
static inline int getch()
{
struct event e = event_get();
if (e.type != evt_keyboard_press)
return KEY_ERR;
return e.kbd.sym;
}