From bbc773ee36d9944e7495ad7fae379176db5b5e40 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Wed, 4 Sep 2024 16:39:29 +0800 Subject: [PATCH] Add support for showing measurement results [GitHub #71 #61] --- include/chsrc.h | 19 ++++++++++++++----- src/chsrc.c | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/chsrc.h b/include/chsrc.h index 9cf9415..ae46ce7 100644 --- a/include/chsrc.h +++ b/include/chsrc.h @@ -20,6 +20,8 @@ static int chsrc_get_cpucore (); +bool ProgMode_CMD_Measure = false; + /* 命令行选项 */ bool CliOpt_IPv6 = false; @@ -322,7 +324,7 @@ query_mirror_exist (SourceInfo *sources, size_t size, char *target, char *input) if (2==size) { char *msg1 = CliOpt_InEnglish ? " is " : " 是 "; - char *msg2 = CliOpt_InEnglish ? " the only mirror site available currently, thanks for their generous support" + char *msg2 = CliOpt_InEnglish ? "'s ONLY mirror available currently, thanks for their generous support" : " 目前唯一可用镜像站,感谢他们的慷慨支持"; const char *name = CliOpt_InEnglish ? sources[1].mirror->abbr : sources[1].mirror->name; @@ -663,12 +665,13 @@ select_mirror_autoly (SourceInfo *sources, size_t size, const char *target_name) if (only_one) { - char *is = CliOpt_InEnglish ? " is " : " 是 "; - char *msg = CliOpt_InEnglish ? "the ONLY mirror available currently, thanks for their generous support" - : " 目前唯一可用镜像站,感谢他们的慷慨支持"; + char *msg1 = CliOpt_InEnglish ? "NOTICE mirror site: " : "镜像站提示: "; + char *is = CliOpt_InEnglish ? " is " : " 是 "; + char *msg2 = CliOpt_InEnglish ? "'s ONLY mirror available currently, thanks for their generous support" + : " 目前唯一可用镜像站,感谢他们的慷慨支持"; const char *name = CliOpt_InEnglish ? sources[fast_idx].mirror->abbr : sources[fast_idx].mirror->name; - chsrc_succ (xy_strjoin (4, name, is, target_name, msg)); + say (xy_strjoin (5, msg1, bdgreen(name), green(is), green(target_name), green(msg2))); } else { @@ -678,6 +681,12 @@ select_mirror_autoly (SourceInfo *sources, size_t size, const char *target_name) say (xy_2strjoin (msg, green(name))); } + // https://github.com/RubyMetric/chsrc/pull/71 + if (ProgMode_CMD_Measure) + { + char *msg = CliOpt_InEnglish ? "URL of above source: " : "镜像源地址: "; + say (xy_2strjoin (msg, green(sources[fast_idx].url))); + } return fast_idx; } diff --git a/src/chsrc.c b/src/chsrc.c index cafdb3f..d23ac03 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -731,6 +731,7 @@ main (int argc, char const *argv[]) chsrc_error (msg); return 1; } + ProgMode_CMD_Measure = true; target = argv[cli_arg_Target_pos]; matched = get_target (target, TargetOp_Measure_Source, NULL); if (!matched) goto not_matched;