-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconsole-colour.h
More file actions
131 lines (100 loc) · 2.35 KB
/
console-colour.h
File metadata and controls
131 lines (100 loc) · 2.35 KB
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
#ifndef _CONSOLE_COLOUR
#define _CONSOLE_COLOUR
#if defined _WIN32 || defined WIN32
#define CONMD_WINDOWS 1
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#include <stddef.h>
enum STATE_E
{
STATE_NONE,
STATE_ESC, // Saw `\x1B`.
STATE_START, // Saw `[`.
STATE_A00, // Saw a number.
STATE_S0, // Saw a semi-colon.
STATE_A10, // Saw a number.
STATE_S1, // Saw a semi-colon.
STATE_A20, // Saw a number.
STATE_S2, // Saw a semi-colon.
STATE_A30, // Saw a number.
STATE_S3, // Saw a semi-colon.
STATE_A40, // Saw a number.
STATE_DONE, // Complete.
STATE_EXTRA_NL, // Insert one extra new line.
STATE_EXTRA_2NL, // Insert two extra new lines.
STATE_EXTRA_SPACE, // Insert one extra space.
STATE_SKIP, // Multi-byte character.
};
#ifdef CONMD_WINDOWS
#include <Windows.h>
#include <stdbool.h>
struct console_colour_stream_s;
typedef int (*OutputC_)(void * data, wchar_t c, struct console_colour_stream_s* const stream);
typedef int (*OutputA_)(void * data, char const* c, int len, struct console_colour_stream_s* const stream);
typedef int (*OutputW_)(void * data, wchar_t const* c, int len, struct console_colour_stream_s* const stream);
typedef void (*OutputColour_)(void * data, unsigned short colour, struct console_colour_stream_s* const stream);
struct console_colour_call_s
{
OutputC_
OutputC;
OutputA_
OutputA;
OutputW_
OutputW;
OutputColour_
OutputColour;
void*
Data;
};
struct console_colour_state_s
{
wchar_t
UnicodeMask;
enum STATE_E
State;
//bool
// Coloured;
WORD
DefaultStyle,
CurrentStyle;
unsigned char
Attr0,
Attr1,
Attr2,
Attr3,
Attr4;
};
struct console_colour_stream_s
{
struct console_colour_call_s *
Call;
struct console_colour_state_s *
State;
};
#else
struct console_colour_state_s
{
wchar_t
UnicodeMask;
enum STATE_E
State;
};
// Empty, just to exist.
struct console_colour_stream_s
{
};
#endif
extern struct console_colour_state_s
gConsoleStreamState;
void ReaddStreamHooks();
void RemoveStreamHooks();
int WriteColouredW(wchar_t const* s, int n, struct console_colour_stream_s* const stream);
int WriteColouredA(char const* s, int n, struct console_colour_stream_s* const stream);
void Backout(struct console_colour_stream_s* const stream);
#ifdef __cplusplus
}
#endif
#endif