libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shell_font.h
Go to the documentation of this file.
1// Copyright 2023 owent
2
3#pragma once
4
5#include <iostream>
6#include <map>
7#include <string>
8
9#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
10# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
11# pragma GCC diagnostic push
12# pragma GCC diagnostic ignored "-Waddress"
13
14# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 600
15# pragma GCC diagnostic ignored "-Wnonnull-compare"
16# endif
17# endif
18#elif defined(__clang__) || defined(__apple_build_version__)
19# pragma clang diagnostic push
20# pragma clang diagnostic ignored "-Waddress"
21#endif
22
28#ifdef _MSC_VER
29# ifndef WIN32_LEAN_AND_MEAN
30# define WIN32_LEAN_AND_MEAN
31# endif
32# include <Windows.h>
33
34# define SHELL_FONT_USING_WIN32_CONSOLE
35
36#endif
37
38namespace util {
39namespace cli {
40
41// 下面是编码表
42//
43// 编码 颜色/动作
44// 0 重新设置属性到缺省设置
45// 1 设置粗体
46// 2 设置一半亮度(模拟彩色显示器的颜色)
47// 4 设置下划线(模拟彩色显示器的颜色)
48// 5 设置闪烁
49// 7 设置反向图象
50// 22 设置一般密度
51// 24 关闭下划线
52// 25 关闭闪烁
53// 27 关闭反向图象
54// 30 设置黑色前景
55// 31 设置红色前景
56// 32 设置绿色前景
57// 33 设置棕色前景
58// 34 设置蓝色前景
59// 35 设置紫色前景
60// 36 设置青色前景
61// 37 设置白色前景
62// 38 在缺省的前景颜色上设置下划线
63// 39 在缺省的前景颜色上关闭下划线
64// 40 设置黑色背景
65// 41 设置红色背景
66// 42 设置绿色背景
67// 43 设置棕色背景
68// 44 设置蓝色背景
69// 45 设置紫色背景
70// 46 设置青色背景
71// 47 设置白色背景
72// 49 设置缺省黑色背景
73
105
107 private:
109
110 public:
115 explicit shell_font(int iFlag = 0);
116 virtual ~shell_font();
117
123 std::string GenerateString(const std::string &strInput);
124
131 static std::string GenerateString(const std::string &strInput, int iFlag);
132
138 static std::string GetStyleCode(int iFlag);
139
144 std::string GetStyleCode();
145
150 static std::string GetStyleCloseCode();
151};
152
154 public:
155 typedef std::ostream stream_t;
157 public:
159
160 private:
162#ifdef SHELL_FONT_USING_WIN32_CONSOLE
163 HANDLE hOsHandle;
164#endif
165 mutable int flag;
166
167 // 进允许内部复制构造
170
171 friend class shell_stream;
172
173 public:
176
177 template <typename Ty>
178 const shell_stream_opr &operator<<(const Ty &v) const {
179 close();
180 (*pOs) << v;
181 return (*this);
182 }
183
184 const shell_stream_opr &operator<<(std::nullptr_t) const;
188 const shell_stream_opr &operator<<(stream_t &(*fn)(stream_t &)) const;
189
190 const shell_stream_opr &open(int flag) const;
191
192 void close() const;
193
194 void reset() const;
195
196 inline operator stream_t &() const { return *pOs; }
197
198 inline operator const stream_t &() const { return *pOs; }
199 };
200
201 public:
202 shell_stream(stream_t &stream = std::cout);
203 shell_stream_opr operator()() const;
204
205 private:
207};
208
209} // namespace cli
210} // namespace util
211
212#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
213# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
214# pragma GCC diagnostic pop
215# endif
216#elif defined(__clang__) || defined(__apple_build_version__)
217# pragma clang diagnostic pop
218#endif
static std::string GetStyleCloseCode()
std::string GenerateString(const std::string &strInput)
std::string GetStyleCode()
shell_stream_opr & operator=(const shell_stream_opr &)
const shell_stream_opr & open(int flag) const
const shell_stream_opr & operator<<(const Ty &v) const
Definition shell_font.h:178
shell_stream_opr operator()() const