-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.h
More file actions
79 lines (65 loc) · 1.79 KB
/
terminal.h
File metadata and controls
79 lines (65 loc) · 1.79 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
#pragma once
#include <iostream>
#include <mutex>
#include <iomanip>
// 用于保护 std::cout 的互斥锁
extern std::mutex cout_mtx;
namespace terminal
{
// 控制台颜色枚举
enum class Color
{
Default = 59, // 默认颜色
White = 231, // 白色
Black = 0, // 黑色
Cyan = 48, // 青色
Blue = 21, // 蓝色
Orange = 208, // 橙色
Yellow = 226, // 黄色
Green = 46, // 绿色
Purple = 93, // 紫色
Red = 196 // 红色
};
// 控制台样式枚举
enum class Style
{
Reset = 0, // 重置样式
Bold, // 粗体
Dim, // 暗淡
Italic, // 斜体
Underline, // 下划线
Blink, // 闪烁
Invert, // 反转
Hidden // 隐藏
};
// 设置控制台颜色的函数
void setColor(Color color, bool isForeground = true);
// 设置控制台样式的函数
void setStyle(Style style);
// 设置光标位置的函数
void setCursor(int row, int col);
// 隐藏光标的函数
void hideCursor();
// 显示光标的函数
void showCursor();
// 清屏的函数
void clearScreen();
// 重置控制台的函数
void reset();
// 绘制计时时间
void drawTick(int64_t minutes, int64_t seconds, int64_t milliseconds);
// 输出文本的函数,线程安全
template <typename T>
void write(T &&text)
{
std::lock_guard<std::mutex> lock(cout_mtx);
std::cout << text;
}
// 输出文本并刷新缓冲区的函数,线程安全
template <typename T>
void fwrite(T &&text)
{
std::lock_guard<std::mutex> lock(cout_mtx);
std::cout << text << std::flush;
}
} // namespace terminal