feat: Added --color flag.

This commit is contained in:
2026-06-26 12:49:58 -04:00
parent a4f4b10a7b
commit ac6c734722
3 changed files with 90 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ Flags :: struct {
help: bool `args:"short=h"`,
config_file: string `args:"name=config-file,short=c"`,
output: Output_Format `args:"short=o"`,
color: Color_Mode,
force: bool `args:"short=f"`,
}
@@ -31,6 +32,12 @@ Output_Format :: enum {
JSON,
}
Color_Mode :: enum {
Auto,
Always,
Never,
}
CommandInfo :: struct {
name: string,
usage: string,
@@ -95,6 +102,13 @@ parse_args :: proc(args: []string, out: io.Stream, err: io.Stream) -> (cmd: Comm
cmd.flags.output = terminal.is_terminal(os.stdout) ? .Table : .JSON
}
if cmd.flags.color == .Auto {
cmd.flags.color = terminal.is_terminal(os.stdout) ? .Always : .Never
}
if cmd.flags.color == .Never {
cmd.out = make_ansi_strip_writer(cmd.out)
}
if cmd.flags.config_file == "" {
// FIXME: Handle err
// TODO: Is this right?
@@ -279,6 +293,11 @@ at before, restore your backup with:
COLOR_FLAGS + "-o, --output" + ANSI_RESET + " 'table'|'json'",
`the format of output data. (default 'table')`,
)
table.row(
&tbl,
COLOR_FLAGS + "--color" + ANSI_RESET + " 'auto'|'always'|'never'",
`Whether or not to colorize output. (default 'auto')`,
)
write_borderless_table(w, &tbl)
fmt.wprintf(