vault backup: 2026-04-15 20:21:46
@@ -0,0 +1,115 @@
|
||||
// terminal_colors.h
|
||||
/**
|
||||
* @file terminal_colors.h
|
||||
* @brief ANSI终端颜色和字体样式控制宏定义
|
||||
* @author 李林峰
|
||||
* @date 2025-07-22
|
||||
* @version 1.0
|
||||
*
|
||||
* 本文件提供了一套完整的ANSI转义码宏定义,用于控制终端文本的颜色、
|
||||
* 背景色和字体样式。支持标准16色、256色模式下的颜色定义,
|
||||
* 以及各种字体样式(加粗、斜体、下划线等)。
|
||||
*
|
||||
* 使用说明:
|
||||
* 1. 包含本头文件:#include "terminal_colors.h"
|
||||
* 2. 使用预定义的宏组合颜色和样式
|
||||
* 3. 每条彩色输出后应使用RESET宏重置终端属性
|
||||
* 4. 推荐使用PRINT_COLOR系列宏,它们会自动处理RESET
|
||||
*
|
||||
* 示例:
|
||||
* printf(RED "红色文本" RESET "\n");
|
||||
* PRINT_COLOR(BOLD BLUE BG_WHITE, "加粗蓝色文本白色背景");
|
||||
* PRINT_ERROR("错误消息");
|
||||
*/
|
||||
|
||||
#ifndef TERMINAL_COLORS_H
|
||||
#define TERMINAL_COLORS_H
|
||||
|
||||
// ==================== 基本控制宏 ====================
|
||||
#define RESET "\033[0m" // 重置所有属性
|
||||
|
||||
// ==================== 常规颜色 ====================
|
||||
#define BLACK "\033[30m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define WHITE "\033[37m"
|
||||
|
||||
// ==================== 亮色 ====================
|
||||
#define BRIGHT_BLACK "\033[90m"
|
||||
#define BRIGHT_RED "\033[91m"
|
||||
#define BRIGHT_GREEN "\033[92m"
|
||||
#define BRIGHT_YELLOW "\033[93m"
|
||||
#define BRIGHT_BLUE "\033[94m"
|
||||
#define BRIGHT_MAGENTA "\033[95m"
|
||||
#define BRIGHT_CYAN "\033[96m"
|
||||
#define BRIGHT_WHITE "\033[97m"
|
||||
|
||||
// ==================== 背景色 ====================
|
||||
#define BG_BLACK "\033[40m"
|
||||
#define BG_RED "\033[41m"
|
||||
#define BG_GREEN "\033[42m"
|
||||
#define BG_YELLOW "\033[43m"
|
||||
#define BG_BLUE "\033[44m"
|
||||
#define BG_MAGENTA "\033[45m"
|
||||
#define BG_CYAN "\033[46m"
|
||||
#define BG_WHITE "\033[47m"
|
||||
|
||||
// ==================== 亮背景色 ====================
|
||||
#define BG_BRIGHT_BLACK "\033[100m"
|
||||
#define BG_BRIGHT_RED "\033[101m"
|
||||
#define BG_BRIGHT_GREEN "\033[102m"
|
||||
#define BG_BRIGHT_YELLOW "\033[103m"
|
||||
#define BG_BRIGHT_BLUE "\033[104m"
|
||||
#define BG_BRIGHT_MAGENTA "\033[105m"
|
||||
#define BG_BRIGHT_CYAN "\033[106m"
|
||||
#define BG_BRIGHT_WHITE "\033[107m"
|
||||
|
||||
// ==================== 字体样式 ====================
|
||||
#define BOLD "\033[1m" // 加粗/高亮
|
||||
#define DIM "\033[2m" // 暗淡
|
||||
#define ITALIC "\033[3m" // 斜体
|
||||
#define UNDERLINE "\033[4m" // 下划线
|
||||
#define BLINK "\033[5m" // 闪烁
|
||||
#define REVERSE "\033[7m" // 反显
|
||||
#define HIDDEN "\033[8m" // 隐藏
|
||||
#define STRIKETHROUGH "\033[9m" // 删除线
|
||||
|
||||
// ==================== 组合宏 ====================
|
||||
#define ERROR_COLOR BOLD RED
|
||||
#define WARNING_COLOR BOLD YELLOW
|
||||
#define SUCCESS_COLOR BOLD GREEN
|
||||
#define INFO_COLOR BOLD BLUE
|
||||
#define DEBUG_COLOR BOLD CYAN
|
||||
|
||||
#define ERROR_BG BOLD RED BG_WHITE
|
||||
#define WARNING_BG BOLD YELLOW BG_BLACK
|
||||
#define SUCCESS_BG BOLD GREEN BG_BLACK
|
||||
#define INFO_BG BOLD BLUE BG_BLACK
|
||||
|
||||
// ==================== 打印宏 ====================
|
||||
/**
|
||||
* @brief 打印带颜色的消息(自动换行和重置)
|
||||
* @param color 颜色/样式组合宏
|
||||
* @param msg 要打印的消息
|
||||
*/
|
||||
#define PRINT_COLOR(color, msg) printf("%s%s" RESET "\n", color, msg)
|
||||
|
||||
/**
|
||||
* @brief 打印带颜色的消息(不换行,自动重置)
|
||||
* @param color 颜色/样式组合宏
|
||||
* @param msg 要打印的消息
|
||||
*/
|
||||
#define PRINT_COLOR_NR(color, msg) printf("%s%s" RESET, color, msg)
|
||||
|
||||
// ==================== 常用消息快捷方式 ====================
|
||||
#define PRINT_ERROR(msg) PRINT_COLOR(ERROR_COLOR, msg)
|
||||
#define PRINT_WARNING(msg) PRINT_COLOR(WARNING_COLOR, msg)
|
||||
#define PRINT_SUCCESS(msg) PRINT_COLOR(SUCCESS_COLOR, msg)
|
||||
#define PRINT_INFO(msg) PRINT_COLOR(INFO_COLOR, msg)
|
||||
#define PRINT_DEBUG(msg) PRINT_COLOR(DEBUG_COLOR, msg)
|
||||
|
||||
#endif // TERMINAL_COLORS_H
|
||||
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 26 KiB |