No color mode for xy

This commit is contained in:
Aoran Zeng
2024-08-23 08:09:39 +08:00
parent 9fde99519b
commit a542e77769
3 changed files with 27 additions and 9 deletions

View File

@@ -7,7 +7,7 @@
* Contributors : Peng Gao <gn3po4g@outlook.com>
* |
* Created on : <2023-08-29>
* Last modified : <2024-08-22>
* Last modified : <2024-08-23>
*
* chsrc 头文件
* ------------------------------------------------------------*/
@@ -18,10 +18,11 @@
#define App_Name "chsrc"
/* 命令行选项 */
bool CliOpt_IPv6 = false;
bool CliOpt_Locally = false;
bool CliOpt_IPv6 = false;
bool CliOpt_Locally = false;
bool CliOpt_InEnglish = false;
bool CliOpt_DryRun = false;
bool CliOpt_DryRun = false;
bool CliOpt_NoColor = false;
/**
* -local 的含义是启用 *项目级* 换源

View File

@@ -8,7 +8,7 @@
* Contributors : Nil Null <nil@null.org>
* |
* Created On : <2023-08-28>
* Last Modified : <2024-08-17>
* Last Modified : <2024-08-23>
*
* xy: 襄阳、咸阳
* Corss-Platform C utilities for CLI applications in Ruby flavor
@@ -17,7 +17,7 @@
#ifndef XY_H
#define XY_H
#define _XY_Version "v0.1.4.1-2024/08/17"
#define _XY_Version "v0.1.4.2-2024/08/23"
#define _XY_Maintain_URL "https://gitee.com/RubyMetric/chsrc/blob/main/include/xy.h"
#include <assert.h>
@@ -29,6 +29,9 @@
#include <string.h>
#include <unistd.h>
/* Global */
bool xy_enable_color = true;
// #define NDEBUG
#ifdef _WIN32
@@ -263,6 +266,12 @@ _xy_str_to_terminal_style (int style, const char *str)
{
char *color_fmt_str = NULL;
if (!xy_enable_color)
{
color_fmt_str = "%s";
goto new_str;
}
switch (style)
{
case _XY_Str_Red:
@@ -291,6 +300,7 @@ _xy_str_to_terminal_style (int style, const char *str)
color_fmt_str = "\e[9m%s\e[0m"; break;
}
new_str:
// -2 把中间%s减掉
size_t len = strlen (color_fmt_str) - 2;
char *buf = malloc (strlen (str) + len + 1);