Skip to content

Commit 82aec8f

Browse files
Update parser.c
1 parent 293b2e7 commit 82aec8f

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

code/logic/parser.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -423,35 +423,21 @@ void fossil_io_parser_parse(fossil_io_parser_palette_t *palette, int argc, char
423423
break;
424424
}
425425

426-
if (strcmp(arg, "--color") == 0) {
427-
FOSSIL_IO_COLOR_ENABLE = 1;
428-
global_flags_processed = 1;
429-
break;
430-
}
431-
else if (strcmp(arg, "--no-color") == 0) {
432-
FOSSIL_IO_COLOR_ENABLE = 0;
433-
global_flags_processed = 1;
434-
break;
435-
}
436-
else if (strcmp(arg, "--color=auto") == 0) {
437-
FOSSIL_IO_COLOR_ENABLE = -1; // let runtime decide
438-
global_flags_processed = 1;
439-
break;
440-
}
441-
else if (strncmp(arg, "--color=", 8) == 0) {
442-
const char *mode = arg + 8;
443-
if (strcmp(mode, "enable") == 0) {
426+
if (strncmp(argv[i], "color=", 6) == 0) {
427+
if (fossil_io_cstr_compare(argv[i] + 6, "enable") == 0) {
444428
FOSSIL_IO_COLOR_ENABLE = 1;
445-
} else if (strcmp(mode, "disable") == 0) {
429+
} else if (fossil_io_cstr_compare(argv[i] + 6, "disable") == 0) {
446430
FOSSIL_IO_COLOR_ENABLE = 0;
447-
} else if (strcmp(mode, "auto") == 0) {
448-
FOSSIL_IO_COLOR_ENABLE = -1;
431+
} else if (fossil_io_cstr_compare(argv[i] + 6, "auto") == 0) {
432+
if (isatty(STDOUT_FILENO)) {
433+
FOSSIL_IO_COLOR_ENABLE = 1;
434+
} else {
435+
FOSSIL_IO_COLOR_ENABLE = 0;
436+
}
449437
} else {
450-
fprintf(stderr, "Unknown --color option: %s\n", mode);
438+
fprintf(stderr, "Unknown color option: %s\n", argv[i] + 6);
451439
exit(EXIT_FAILURE);
452440
}
453-
global_flags_processed = 1;
454-
break;
455441
}
456442

457443
if (strcmp(arg, "--version") == 0) {

0 commit comments

Comments
 (0)