Skip to content

Commit 9031591

Browse files
committed
使用 xy.enable_color
1 parent 60ad6c1 commit 9031591

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

lib/xy.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
#endif
5959

6060

61-
/* 全局变量 */
62-
bool xy_enable_color = true;
63-
64-
/* 由 xy_init() 赋值 */
6561
bool xy_on_windows = false;
6662
bool xy_on_linux = false;
6763
bool xy_on_macos = false;
@@ -70,6 +66,34 @@ bool xy_on_android = false;
7066

7167
char *xy_os_devnull = NULL;
7268

69+
/* 全局变量 与 全局状态 */
70+
struct
71+
{
72+
bool enable_color;
73+
74+
bool on_windows;
75+
bool on_linux;
76+
bool on_macos;
77+
bool on_bsd;
78+
bool on_android;
79+
80+
char *os_devnull;
81+
}
82+
xy =
83+
{
84+
.enable_color = true,
85+
86+
/* 由 xy_init() 赋值 */
87+
.on_windows = false,
88+
.on_linux = false,
89+
.on_macos = false,
90+
.on_bsd = false,
91+
.on_android = false,
92+
93+
.os_devnull = NULL
94+
};
95+
96+
7397

7498
#ifdef _WIN32
7599
#define XY_Build_On_Windows 1
@@ -388,7 +412,7 @@ _xy_str_to_terminal_style (int style, const char *str)
388412
{
389413
char *color_fmt_str = NULL;
390414

391-
if (!xy_enable_color)
415+
if (!xy.enable_color)
392416
{
393417
color_fmt_str = "%s";
394418
goto new_str;

src/chsrc-main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ main (int argc, char const *argv[])
716716
else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour"))
717717
{
718718
ProgMode.NoColorMode = true;
719-
xy_enable_color = false;
719+
xy.enable_color = false;
720720
}
721721
else if ( xy_streql (argv[i], "-h")
722722
|| xy_streql (argv[i], "-help")

test/xy.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Test Authors : 曾奥然 <[email protected]>
66
* Contributors : Mikachu2333 <[email protected]>
77
* Created On : <2023-08-30>
8-
* Last Modified : <2025-08-26>
8+
* Last Modified : <2025-08-27>
99
*
1010
* Test xy.h
1111
* ------------------------------------------------------------*/
@@ -30,6 +30,9 @@ main (int argc, char const *argv[])
3030
{
3131
xy_init ();
3232

33+
// 关闭颜色
34+
// xy.enable_color = false;
35+
3336
println (xy_os_depend_str ("Hello, Windows!", "Hello, Unix!"));
3437

3538
println (3);

0 commit comments

Comments
 (0)