cmake可见性和AppArmor示例
This commit is contained in:
parent
0eeb4a7bb6
commit
4b4b933e3d
19 changed files with 661 additions and 0 deletions
4
cmake/visibility/color/include/rgb_convert.h
Normal file
4
cmake/visibility/color/include/rgb_convert.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
// 内部工具:把 RGB 分量拼成 ANSI 真彩色转义码。
|
||||
// 供 color 库内部多个 .cpp 共享,不属于对外 API。
|
||||
const char* rgbToAnsi(int r, int g, int b);
|
||||
11
cmake/visibility/color/public/color/color.h
Normal file
11
cmake/visibility/color/public/color/color.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
enum class Color { Red, Green, Blue };
|
||||
|
||||
const char* colorCode(Color c);
|
||||
|
||||
// 这个宏出现在公开头文件里,直接决定 API 的形状(多不多一个函数)。
|
||||
// 因此该宏必须对"用 color 的人"同样可见 → CMake 里标 PUBLIC。
|
||||
#ifdef COLOR_ENABLE_BRIGHT
|
||||
const char* brightColorCode(Color c); // 高亮色版本
|
||||
#endif
|
||||
22
cmake/visibility/color/src/color.cpp
Normal file
22
cmake/visibility/color/src/color.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "color/color.h"
|
||||
#include "rgb_convert.h" // 内部头:能找到它,靠的是 PRIVATE 的 include/ 搜索路径
|
||||
|
||||
const char* colorCode(Color c) {
|
||||
switch (c) {
|
||||
case Color::Red: return rgbToAnsi(205, 49, 49);
|
||||
case Color::Green: return rgbToAnsi(13, 188, 121);
|
||||
case Color::Blue: return rgbToAnsi(36, 114, 200);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
#ifdef COLOR_ENABLE_BRIGHT
|
||||
const char* brightColorCode(Color c) {
|
||||
switch (c) {
|
||||
case Color::Red: return rgbToAnsi(241, 76, 76);
|
||||
case Color::Green: return rgbToAnsi(35, 209, 139);
|
||||
case Color::Blue: return rgbToAnsi(59, 142, 234);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#endif
|
||||
8
cmake/visibility/color/src/rgb_convert.cpp
Normal file
8
cmake/visibility/color/src/rgb_convert.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "rgb_convert.h"
|
||||
#include <cstdio>
|
||||
|
||||
const char* rgbToAnsi(int r, int g, int b) {
|
||||
static char buf[32]; // demo 从简,非线程安全
|
||||
std::snprintf(buf, sizeof(buf), "\033[38;2;%d;%d;%dm", r, g, b);
|
||||
return buf;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue