forked from alberthdev/spasm-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.cpp
44 lines (37 loc) · 1.04 KB
/
console.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
#include "stdafx.h"
#include "console.h"
#include "spasm.h"
//saved console attributes, to be restored on exit
WORD user_attributes;
void restore_console_attributes_at_exit () {
if (!use_colors) return;
#ifdef WIN32
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), user_attributes);
#elif !defined(MACVER)
printf ("\x1b[0m");
#endif
}
void restore_console_attributes (WORD orig_attributes) {
if (!use_colors) return;
#ifdef WIN32
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), orig_attributes);
#elif !defined(MACVER)
printf ("\x1b[0m");
#endif
}
WORD save_console_attributes () {
#ifdef WIN32
CONSOLE_SCREEN_BUFFER_INFO csbiScreenBufferInfo;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbiScreenBufferInfo);
return csbiScreenBufferInfo.wAttributes;
#endif
}
BOOL set_console_attributes (unsigned short attr) {
if (!use_colors) return true;
#ifdef WIN32
return SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), (WORD)attr);
#elif !defined(MACVER)
printf ("\x1b[1;%dm", attr);
return true;
#endif
}