Use simpler function names

This commit is contained in:
Aoran Zeng 2024-08-19 11:53:10 +08:00
parent 51d08a5746
commit 96c44191b3
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 54 additions and 54 deletions

View File

@ -58,22 +58,22 @@ bool CliOpt_DryRun = false;
#define chsrc_warn2(str) xy_warn_brkt(App_Name,"警告",str)
#define chsrc_error2(str) xy_error_brkt(App_Name,"错误",str)
#define to_red(str) xy_str_to_red(str)
#define to_blue(str) xy_str_to_blue(str)
#define to_green(str) xy_str_to_green(str)
#define to_yellow(str) xy_str_to_yellow(str)
#define to_purple(str) xy_str_to_purple(str)
#define to_bold(str) xy_str_to_bold(str)
#define to_boldred(str) xy_str_to_bold(xy_str_to_red(str))
#define to_boldblue(str) xy_str_to_bold(xy_str_to_blue(str))
#define to_boldgreen(str) xy_str_to_bold(xy_str_to_green(str))
#define to_boldyellow(str) xy_str_to_bold(xy_str_to_yellow(str))
#define to_boldpurple(str) xy_str_to_bold(xy_str_to_purple(str))
#define red(str) xy_str_to_red(str)
#define blue(str) xy_str_to_blue(str)
#define green(str) xy_str_to_green(str)
#define yellow(str) xy_str_to_yellow(str)
#define purple(str) xy_str_to_purple(str)
#define bold(str) xy_str_to_bold(str)
#define bred(str) xy_str_to_bold(xy_str_to_red(str))
#define bblue(str) xy_str_to_bold(xy_str_to_blue(str))
#define bgreen(str) xy_str_to_bold(xy_str_to_green(str))
#define byellow(str) xy_str_to_bold(xy_str_to_yellow(str))
#define bpurple(str) xy_str_to_bold(xy_str_to_purple(str))
void
chsrc_note2 (const char* str)
{
xy_log_brkt (to_yellow (App_Name), to_boldyellow ("提示"), to_yellow (str));
xy_log_brkt (yellow (App_Name), byellow ("提示"), yellow (str));
}
#define YesMark "✓"
@ -106,13 +106,13 @@ log_check_result (const char *check_what, const char *check_type, bool exist)
if (!exist)
{
xy_log_brkt (App_Name, to_boldred (chk_msg), xy_strjoin (5,
to_red (NoMark " "), check_type, " ", to_red (check_what), not_exist_msg));
xy_log_brkt (App_Name, bred (chk_msg), xy_strjoin (5,
red (NoMark " "), check_type, " ", red (check_what), not_exist_msg));
}
else
{
xy_log_brkt (App_Name, to_boldgreen (chk_msg), xy_strjoin (5,
to_green (YesMark " "), check_type, " ", to_green (check_what), exist_msg));
xy_log_brkt (App_Name, bgreen (chk_msg), xy_strjoin (5,
green (YesMark " "), check_type, " ", green (check_what), exist_msg));
}
}
@ -141,13 +141,13 @@ log_cmd_result (bool result, int ret_code)
}
if (result)
xy_log_brkt (to_green (App_Name), to_boldgreen (run_msg), to_green (succ_msg));
xy_log_brkt (green (App_Name), bgreen (run_msg), green (succ_msg));
else
{
char buf[8] = {0};
sprintf (buf, "%d", ret_code);
char *log = xy_2strjoin (to_red (fail_msg), to_boldred (buf));
xy_log_brkt (to_red (App_Name), to_boldred (run_msg), log);
char *log = xy_2strjoin (red (fail_msg), bred (buf));
xy_log_brkt (red (App_Name), bred (run_msg), log);
}
}
@ -323,11 +323,11 @@ to_human_readable_speed (double speed)
sprintf (buf, "%.2f %s", speed, scale[i]);
char *new = NULL;
if (i <= 1 ) new = to_red (buf);
if (i <= 1 ) new = red (buf);
else
{
if (i == 2 && speed < 2.00) new = to_yellow (buf);
else new = to_green (buf);
if (i == 2 && speed < 2.00) new = yellow (buf);
else new = green (buf);
}
return new;
}
@ -383,7 +383,7 @@ measure_speed (const char *url)
if (200!=http_code)
{
char* httpcodestr = to_yellow (xy_2strjoin ("HTTP码 ", buf));
char* httpcodestr = yellow (xy_2strjoin ("HTTP码 ", buf));
puts (xy_strjoin (3, speedstr, " | ", httpcodestr));
}
else
@ -488,7 +488,7 @@ auto_select_ (SourceInfo *sources, size_t size, const char *target_name)
else
{
char *fast_msg = CliOpt_InEnglish ? "FASTEST mirror site: " : "最快镜像站: ";
say (xy_2strjoin (fast_msg, to_green (sources[fast_idx].mirror->name)));
say (xy_2strjoin (fast_msg, green (sources[fast_idx].mirror->name)));
}
@ -578,7 +578,7 @@ confirm_source (SourceInfo *source)
else
{
char *msg = CliOpt_InEnglish ? "SELECT mirror site: " : "选中镜像站: ";
say (xy_strjoin (5, msg, to_green (source->mirror->abbr), " (", to_green (source->mirror->code), ")"));
say (xy_strjoin (5, msg, green (source->mirror->abbr), " (", green (source->mirror->code), ")"));
}
split_between_source_changing_process;
@ -638,7 +638,7 @@ chsrc_conclude (SourceInfo *source, const char *last_word)
{
char *msg = CliOpt_InEnglish ? MSG_EN_FULLY_AUTO MSG_EN_THANKS \
: MSG_CN_FULLY_AUTO ", " MSG_CN_THANKS;
chsrc_log (xy_2strjoin (msg, to_purple (source->mirror->name)));
chsrc_log (xy_2strjoin (msg, purple (source->mirror->name)));
}
}
else
@ -651,7 +651,7 @@ chsrc_conclude (SourceInfo *source, const char *last_word)
{
// source_is_upstream (source)
char *msg = CliOpt_InEnglish ? "Has been reset to the upstream default source" : "已重置为上游默认源";
chsrc_log (to_purple (msg));
chsrc_log (purple (msg));
}
else if (xy_streql (ChsrcTypeSemiAuto, last_word))
{
@ -667,7 +667,7 @@ chsrc_conclude (SourceInfo *source, const char *last_word)
{
char *msg = CliOpt_InEnglish ? MSG_EN_SEMI_AUTO MSG_EN_STILL MSG_EN_THANKS \
: MSG_CN_SEMI_AUTO ", " MSG_CN_STILL "" MSG_CN_THANKS;
chsrc_log (xy_2strjoin (msg, to_purple (source->mirror->name)));
chsrc_log (xy_2strjoin (msg, purple (source->mirror->name)));
}
}
else
@ -694,7 +694,7 @@ chsrc_conclude (SourceInfo *source, const char *last_word)
{
char *msg = CliOpt_InEnglish ? MSG_EN_CONSTRAINT MSG_EN_THANKS \
: MSG_CN_CONSTRAINT ", " MSG_CN_THANKS;
chsrc_log (xy_2strjoin (msg, to_purple (source->mirror->name)));
chsrc_log (xy_2strjoin (msg, purple (source->mirror->name)));
}
}
else
@ -717,7 +717,7 @@ chsrc_conclude (SourceInfo *source, const char *last_word)
else
{
char *msg = CliOpt_InEnglish ? MSG_EN_THANKS : MSG_CN_THANKS;
chsrc_log (xy_2strjoin (msg, to_purple (source->mirror->name)));
chsrc_log (xy_2strjoin (msg, purple (source->mirror->name)));
}
}
else
@ -767,9 +767,9 @@ static void
chsrc_run (const char *cmd, int run_option)
{
if (CliOpt_InEnglish)
xy_log_brkt (to_blue (App_Name), to_boldblue ("RUN"), to_blue (cmd));
xy_log_brkt (blue (App_Name), bblue ("RUN"), blue (cmd));
else
xy_log_brkt (to_blue (App_Name), to_boldblue ("运行"), to_blue (cmd));
xy_log_brkt (blue (App_Name), bblue ("运行"), blue (cmd));
if (CliOpt_DryRun)
{

View File

@ -16,8 +16,8 @@
* chsrc: Change Source
* ------------------------------------------------------------*/
#define Chsrc_Version "0.1.7.3"
#define Chsrc_Release_Date "2024/08/18"
#define Chsrc_Version "0.1.7.3.dev1"
#define Chsrc_Release_Date "2024/08/19"
#define Chsrc_Banner_Version "v" Chsrc_Version "-" Chsrc_Release_Date
#define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc"
#define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc"
@ -166,13 +166,13 @@ void
cli_print_supported_targets ()
{
chsrc_info ("支持对以下目标换源 (同一行表示这几个命令兼容)"); br();
say (to_blue ("编程语言开发"));
say (blue ("编程语言开发"));
say ("-------------------------");
cli_print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
say (to_blue ("操作系统"));
say (blue ("操作系统"));
say ("-------------------------");
cli_print_supported_targets_ (os_systems, xy_arylen(os_systems));
say (to_blue ("软件"));
say (blue ("软件"));
say ("-------------------------");
cli_print_supported_targets_ (wr_softwares, xy_arylen(wr_softwares));
}
@ -222,19 +222,19 @@ cli_print_target_available_sources (SourceInfo sources[], size_t size)
void
cli_print_target_features (FeatInfo f, const char *input_target_name)
{
say (to_boldpurple("\nFeatures:\n"));
say (bpurple("\nFeatures:\n"));
char *get_msg = xy_2strjoin (" Get: 查看当前源状态 | chsrc get ", input_target_name);
if (f.can_get) printf (" %s%s\n", to_boldgreen(YesMark), to_purple(get_msg));
else printf (" %s%s\n", to_boldred(NoMark), get_msg);br();
if (f.can_get) printf (" %s%s\n", bgreen(YesMark), purple(get_msg));
else printf (" %s%s\n", bred(NoMark), get_msg);br();
char *reset_msg = xy_2strjoin (" Reset: 重置回默认源 | chsrc reset ", input_target_name);
if (f.can_reset) printf (" %s%s\n", to_boldgreen(YesMark), to_purple(reset_msg));
else printf (" %s%s\n", to_boldred(NoMark), reset_msg);br();
if (f.can_reset) printf (" %s%s\n", bgreen(YesMark), purple(reset_msg));
else printf (" %s%s\n", bred(NoMark), reset_msg);br();
char *user_define_msg = xy_strjoin (4, " UserDefine: 用户自定义换源URL | chsrc set ", input_target_name, " https://user-define-url.org/", input_target_name);
if (f.can_user_define) printf (" %s%s\n", to_boldgreen(YesMark), to_purple(user_define_msg));
else printf (" %s%s\n", to_boldred(NoMark), user_define_msg);br();
if (f.can_user_define) printf (" %s%s\n", bgreen(YesMark), purple(user_define_msg));
else printf (" %s%s\n", bred(NoMark), user_define_msg);br();
char *locally_msg = xy_2strjoin (" Locally: 仅对本项目换源 | chsrc set -local ", input_target_name);
@ -242,26 +242,26 @@ cli_print_target_features (FeatInfo f, const char *input_target_name)
switch (f.stcan_locally)
{
case CanNotFully:
printf (" %s%s\n", to_boldred(NoMark), locally_msg);br();
printf (" %s%s\n", bred(NoMark), locally_msg);br();
break;
case CanFully:
printf (" %s%s\n", to_boldgreen(YesMark), to_purple(locally_msg));br();
printf (" %s%s\n", bgreen(YesMark), purple(locally_msg));br();
break;
case CanSemi:
printf (" %s%s\n\n %s\n", to_boldgreen(SemiYesMark), to_purple(locally_msg), f.locally);br();
printf (" %s%s\n\n %s\n", bgreen(SemiYesMark), purple(locally_msg), f.locally);br();
break;
default:
xy_unreach;
}
char *english_msg = xy_2strjoin (" English: 英文输出 | chsrc set -en ", input_target_name);
// if (f.can_english) printf (" %s%s\n", to_boldgreen(YesMark), to_purple(english_msg));
// else printf (" %s%s\n", to_boldred(NoMark), english_msg);
// if (f.can_english) printf (" %s%s\n", bgreen(YesMark), purple(english_msg));
// else printf (" %s%s\n", bred(NoMark), english_msg);
if (f.note)
{
printf ("%s%s\n", to_boldyellow ("备注: "), to_boldyellow (f.note));
printf ("%s%s\n", byellow ("备注: "), byellow (f.note));
}
}
@ -283,7 +283,7 @@ void
cli_print_help ()
{
say (xy_strjoin (3, "chsrc: Change Source (GPLv3+) ",
to_purple (Chsrc_Banner_Version), " by RubyMetric"));
purple (Chsrc_Banner_Version), " by RubyMetric"));
br();
for (int i=0; i<xy_arylen (Chsrc_Usage); i++)
{
@ -406,8 +406,8 @@ get_target (const char *input, TargetOp code, char *option)
}
else if (TargetOp_List_Config==code)
{
say (to_boldblue(xy_strjoin (3, "指定使用某源,请使用 chsrc set ", input, " <code>\n")));
say (to_boldgreen("Available Sources: \n"));
say (bblue(xy_strjoin (3, "指定使用某源,请使用 chsrc set ", input, " <code>\n")));
say (bgreen("Available Sources: \n"));
// chsrc_info (xy_strjoin (3, "下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " <code>\n"));
printf (" %-14s%-35s%-43s ", "code", "镜像站简写", "换源URL"); say ("镜像站名称");
say ("--------- -------------- ----------------------------------------------- ---------------------");
@ -469,7 +469,7 @@ main (int argc, char const *argv[])
else if (xy_streql (argv[i], "-dry"))
{
CliOpt_DryRun = true;
chsrc_log (to_boldyellow ("**开启Dry Run模式模拟换源过程(跳过测速),命令仅打印并不运行**\n"));
chsrc_log (byellow ("**开启Dry Run模式模拟换源过程(跳过测速),命令仅打印并不运行**\n"));
}
else
{