使用 xy.enable_color

This commit is contained in:
Aoran Zeng 2025-08-27 11:53:08 +08:00
parent 60ad6c1fc6
commit 90315917e9
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 34 additions and 7 deletions

View File

@ -58,10 +58,6 @@
#endif #endif
/* 全局变量 */
bool xy_enable_color = true;
/* 由 xy_init() 赋值 */
bool xy_on_windows = false; bool xy_on_windows = false;
bool xy_on_linux = false; bool xy_on_linux = false;
bool xy_on_macos = false; bool xy_on_macos = false;
@ -70,6 +66,34 @@ bool xy_on_android = false;
char *xy_os_devnull = NULL; char *xy_os_devnull = NULL;
/* 全局变量 与 全局状态 */
struct
{
bool enable_color;
bool on_windows;
bool on_linux;
bool on_macos;
bool on_bsd;
bool on_android;
char *os_devnull;
}
xy =
{
.enable_color = true,
/* 由 xy_init() 赋值 */
.on_windows = false,
.on_linux = false,
.on_macos = false,
.on_bsd = false,
.on_android = false,
.os_devnull = NULL
};
#ifdef _WIN32 #ifdef _WIN32
#define XY_Build_On_Windows 1 #define XY_Build_On_Windows 1
@ -388,7 +412,7 @@ _xy_str_to_terminal_style (int style, const char *str)
{ {
char *color_fmt_str = NULL; char *color_fmt_str = NULL;
if (!xy_enable_color) if (!xy.enable_color)
{ {
color_fmt_str = "%s"; color_fmt_str = "%s";
goto new_str; goto new_str;

View File

@ -716,7 +716,7 @@ main (int argc, char const *argv[])
else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour")) else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour"))
{ {
ProgMode.NoColorMode = true; ProgMode.NoColorMode = true;
xy_enable_color = false; xy.enable_color = false;
} }
else if ( xy_streql (argv[i], "-h") else if ( xy_streql (argv[i], "-h")
|| xy_streql (argv[i], "-help") || xy_streql (argv[i], "-help")

View File

@ -5,7 +5,7 @@
* Test Authors : <ccmywish@qq.com> * Test Authors : <ccmywish@qq.com>
* Contributors : Mikachu2333 <mikachu.23333@zohomail.com> * Contributors : Mikachu2333 <mikachu.23333@zohomail.com>
* Created On : <2023-08-30> * Created On : <2023-08-30>
* Last Modified : <2025-08-26> * Last Modified : <2025-08-27>
* *
* Test xy.h * Test xy.h
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
@ -30,6 +30,9 @@ main (int argc, char const *argv[])
{ {
xy_init (); xy_init ();
// 关闭颜色
// xy.enable_color = false;
println (xy_os_depend_str ("Hello, Windows!", "Hello, Unix!")); println (xy_os_depend_str ("Hello, Windows!", "Hello, Unix!"));
println (3); println (3);