mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-17 01:22:45 +08:00
No color mode for xy
This commit is contained in:
parent
9fde99519b
commit
a542e77769
|
@ -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 的含义是启用 *项目级* 换源
|
||||
|
|
14
include/xy.h
14
include/xy.h
|
@ -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);
|
||||
|
|
13
src/chsrc.c
13
src/chsrc.c
|
@ -11,7 +11,7 @@
|
|||
* | BlockLune <blocklune@gmail.com>
|
||||
* |
|
||||
* Created On : <2023-08-28>
|
||||
* Last Modified : <2024-08-22>
|
||||
* Last Modified : <2024-08-23>
|
||||
*
|
||||
* chsrc: Change Source —— 全平台通用命令行换源工具
|
||||
* ------------------------------------------------------------*/
|
||||
|
@ -124,7 +124,8 @@ Chsrc_Usage[] = {
|
|||
"-dry Dry Run,模拟换源过程,命令仅打印并不运行",
|
||||
"-ipv6 使用IPv6测速",
|
||||
"-local 仅对本项目而非全局换源 (通过ls <target>查看支持情况)",
|
||||
"-en(glish) 使用英文输出\n",
|
||||
"-en(glish) 使用英文输出",
|
||||
"-no-color 无颜色输出\n",
|
||||
|
||||
"维护: <" Chsrc_Maintain_URL ">"
|
||||
};
|
||||
|
@ -155,7 +156,8 @@ Chsrc_Usage_English[] = {
|
|||
"-dry Dry Run. Simulate the source changing process, command only prints, not run",
|
||||
"-ipv6 Speed measurement using IPv6",
|
||||
"-local Change source only for this project rather than globally (Via ls <target>)",
|
||||
"-en(glish) Output in English\n",
|
||||
"-en(glish) Output in English",
|
||||
"-no-color Output without color\n",
|
||||
|
||||
"Maintain: <" Chsrc_Maintain_URL ">"
|
||||
};
|
||||
|
@ -523,6 +525,11 @@ main (int argc, char const *argv[])
|
|||
CliOpt_DryRun = true;
|
||||
chsrc_log (bdyellow ("**开启Dry Run模式,模拟换源过程(跳过测速),命令仅打印并不运行**\n"));
|
||||
}
|
||||
else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour"))
|
||||
{
|
||||
CliOpt_NoColor = true;
|
||||
xy_enable_color = false;
|
||||
}
|
||||
else if (xy_streql (argv[i], "-h")
|
||||
|| xy_streql (argv[i], "-help")
|
||||
|| xy_streql (argv[i], "--help"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user