Make speed result same line

This commit is contained in:
Aoran Zeng 2023-09-05 15:29:53 +08:00
parent 5ba6146ca0
commit cf20526f1c
2 changed files with 36 additions and 35 deletions

17
chsrc.c
View File

@ -101,7 +101,15 @@ to_human_readable_speed (double speed)
} }
char* buf = xy_malloc0(64); char* buf = xy_malloc0(64);
sprintf(buf, "%.2f %s", speed, scale[i]); sprintf(buf, "%.2f %s", speed, scale[i]);
return buf;
char* new = NULL;
if (i <= 1 ) new = xy_str_to_red(buf);
else
{
if (i == 2 && speed < 2.00) new = xy_str_to_yellow(buf);
else new = xy_str_to_green(buf);
}
return new;
} }
@ -138,9 +146,10 @@ test_speed_url (const char* url)
char* speedstr = to_human_readable_speed(speed); char* speedstr = to_human_readable_speed(speed);
if (200!=http_code) { if (200!=http_code) {
xy_warn (xy_strjoin(4, "chsrc: 速度 ", speedstr, " | HTTP码 " , http_code)); char* httpcodestr = xy_str_to_yellow(xy_2strjoin("HTTP码 ", buf));
puts (xy_strjoin(3, speedstr, " | ", httpcodestr));
} else { } else {
xy_info (xy_2strjoin("chsrc: 速度 ", speedstr)); puts (speedstr);
} }
return speed; return speed;
} }
@ -168,7 +177,7 @@ lets_test_speed_ (source_info* sources, size_t size, const char* target)
xy_warn ("chsrc: 跳过该站点"); xy_warn ("chsrc: 跳过该站点");
speed = 0; speed = 0;
} else { } else {
xy_info (xy_2strjoin("chsrc: 测速 ", src.mirror->site)); printf (xy_strjoin(3, "chsrc: 测速 ", src.mirror->site , " ... "));
speed = test_speed_url (url); speed = test_speed_url (url);
} }
speeds[i] = speed; speeds[i] = speed;

54
chsrc.h
View File

@ -118,14 +118,14 @@ typedef struct {
/** /**
* *
* *
* * @note
*/ */
/** /**
* 2023-09-02 * 2023-09-02
* *
* Ruby China * @note Ruby China
*/ */
static source_info static source_info
pl_ruby_sources[] = { pl_ruby_sources[] = {
@ -140,19 +140,18 @@ pl_ruby_sources[] = {
/** /**
* 2023-08-29 * 2023-09-05
* *
* Zjupypi在校外访问会自动转向Tuna * @note Zjupypi在校外访问会自动转向Tuna
* *
* TODO: 1. Python用户协助 * TODO:
* 2.
*/ */
pl_python_sources[] = { pl_python_sources[] = {
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/pypi/web/simple"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/pypi/web/simple"},
{&Tuna, "https://pypi.tuna.tsinghua.edu.cn/simple"},
{&Lzuoss, "https://mirror.lzu.edu.cn/pypi/web/simple"}, {&Lzuoss, "https://mirror.lzu.edu.cn/pypi/web/simple"},
{&Jlu, "https://mirrors.jlu.edu.cn/pypi/web/simple"}, {&Jlu, "https://mirrors.jlu.edu.cn/pypi/web/simple"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/pypi/web/simple"} {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/pypi/web/simple"},
{&Tuna, "https://pypi.tuna.tsinghua.edu.cn/simple"},
}, },
@ -162,7 +161,7 @@ pl_python_sources[] = {
* *
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu, * Sjtug, Tuna, Lzuoss, Jlu, Bfsu,
* *
* npm的名 * @note npm的名
*/ */
pl_nodejs_sources[] = { pl_nodejs_sources[] = {
{&Ali, "https://registry.npmmirror.com"}, {&Ali, "https://registry.npmmirror.com"},
@ -171,17 +170,15 @@ pl_nodejs_sources[] = {
/** /**
* 2023-08-30 * 2023-09-05
* *
* https://help.mirrors.cernet.edu.cn/CPAN/ * : https://help.mirrors.cernet.edu.cn/CPAN/
*
* TODO: Perl用户协助
*/ */
pl_perl_sources[] = { pl_perl_sources[] = {
{&Ali, "https://mirrors.aliyun.com/CPAN/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CPAN/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/CPAN/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/CPAN/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/CPAN/"},
{&Bjtu, "https://mirror.bjtu.edu.cn/cpan/"}, {&Bjtu, "https://mirror.bjtu.edu.cn/cpan/"},
{&Ali, "https://mirrors.aliyun.com/CPAN/"},
{&Lzuoss, "https://mirror.lzu.edu.cn/CPAN/"} {&Lzuoss, "https://mirror.lzu.edu.cn/CPAN/"}
}, },
@ -203,10 +200,9 @@ pl_r_sources[] = {
/** /**
* 2023-08-30 * 2023-09-05
* *
* TODO: 1. Julia用户协助 * @note
* 2.
*/ */
pl_julia_sources[] = { pl_julia_sources[] = {
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/julia"}, {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/julia"},
@ -218,7 +214,7 @@ pl_julia_sources[] = {
/** /**
* 2023-09-04 * 2023-09-04
* *
* TODO: 1. * @note
*/ */
pl_go_sources[] = { pl_go_sources[] = {
{&GoProxyCN, "https://goproxy.cn"}, {&GoProxyCN, "https://goproxy.cn"},
@ -245,9 +241,8 @@ pl_rust_sources[] = {
/** /**
* 2023-08-30 * 2023-08-30
* *
* TODO: 1. Java用户协助 * @note
* 2. *
* 3.
*/ */
pl_java_sources[] = { pl_java_sources[] = {
{&Ali, "https://maven.aliyun.com/repository/public/"} {&Ali, "https://maven.aliyun.com/repository/public/"}
@ -257,11 +252,9 @@ pl_java_sources[] = {
/** /**
* 2023-08-30 * 2023-08-30
* *
* * @note
* *
* TODO: 1. Java用户协助 * @note
* 2.
* 3.
*/ */
pl_dotnet_sources[] = { pl_dotnet_sources[] = {
{&NugetOrg, "https://www.nuget.org/api/v2/"} {&NugetOrg, "https://www.nuget.org/api/v2/"}
@ -272,8 +265,7 @@ pl_dotnet_sources[] = {
/** /**
* 2023-09-04 * 2023-09-04
* *
* TODO: 1. PHP用户协助 * @note
* 2.
*/ */
pl_php_sources[] = { pl_php_sources[] = {
{&Ali, "https://mirrors.aliyun.com/composer/"}, {&Ali, "https://mirrors.aliyun.com/composer/"},
@ -412,13 +404,13 @@ chsrc_logcmd (const char* cmd)
void void
chsrc_say_selection (source_info* source) chsrc_say_selection (source_info* source)
{ {
xy_info (xy_strjoin(5, "chsrc: 选中镜像站", source->mirror->abbr, " (", source->mirror->code, ")")); xy_info (xy_strjoin(5, "chsrc: 选中镜像站: ", source->mirror->abbr, " (", source->mirror->code, ")"));
} }
void void
chsrc_say_thanks (source_info* source) chsrc_say_thanks (source_info* source)
{ {
xy_success(xy_2strjoin("chsrc: 感谢镜像提供方", source->mirror->name)); xy_success(xy_2strjoin("chsrc: 感谢镜像提供方: ", source->mirror->name));
} }