-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathterm_util.cpp
More file actions
38 lines (32 loc) · 949 Bytes
/
term_util.cpp
File metadata and controls
38 lines (32 loc) · 949 Bytes
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
#include "term_util.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <mutex>
#include <paramkit.h>
std::mutex g_stdOutMutex;
bool hh::util::get_current_color(int descriptor, WORD &color)
{
HANDLE hConsole = GetStdHandle(descriptor);
if (hConsole == INVALID_HANDLE_VALUE || hConsole == NULL) {
return false;
}
return paramkit::get_console_color(hConsole, color);
}
WORD hh::util::set_color(WORD color)
{
WORD old_color = 7;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE || hConsole == NULL) {
return old_color;
}
if (paramkit::get_console_color(hConsole, old_color)) {
SetConsoleTextAttribute(hConsole, color);
}
return old_color;
}
void hh::util::print_in_color(WORD color, const std::string &text)
{
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
paramkit::print_in_color(color, text);
}