-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_utils.h
More file actions
52 lines (46 loc) · 1.26 KB
/
console_utils.h
File metadata and controls
52 lines (46 loc) · 1.26 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
#pragma once
#include <string>
#include <iostream>
#include <windows.h>
namespace ConsoleColors
{
enum Color
{
DEFAULT = 7, // 默认白色
GREEN = 10, // 绿色
RED = 12, // 红色
YELLOW = 14, // 黄色
BLUE = 9, // 蓝色
CYAN = 11, // 青色
MAGENTA = 13, // 洋红色
BRIGHT_GREEN = 10, // 亮绿色
BRIGHT_RED = 12, // 亮红色
BRIGHT_YELLOW = 14, // 亮黄色
BRIGHT_BLUE = 9, // 亮蓝色
BRIGHT_CYAN = 11, // 亮青色
BRIGHT_MAGENTA = 13 // 亮洋红色
};
// 设置控制台文本颜色
inline void SetColor(Color color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
// 重置为默认颜色
inline void Reset()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), DEFAULT);
}
// 带颜色的输出辅助函数
inline void Print(Color color, const std::string &text)
{
SetColor(color);
std::cout << text;
Reset();
}
inline void PrintLn(Color color, const std::string &text)
{
SetColor(color);
std::cout << text << std::endl;
Reset();
}
}