Color Modes
Three Modes
Section titled “Three Modes”output.ColorModeAuto // Detects TTY, respects NO_COLOR / CI / FORCE_COLORoutput.ColorModeAlways // Always emit ANSI colorsoutput.ColorModeNever // Never emit ANSI colorsWiring Mechanisms
Section titled “Wiring Mechanisms”Different renderers accept color mode through different APIs:
Functional option (terminal tables)
Section titled “Functional option (terminal tables)”tbl := table.New(table.WithColorMode(output.ColorModeAlways))Setter (ASCII tree, markdown)
Section titled “Setter (ASCII tree, markdown)”renderer := tree.NewASCIITreeRenderer()renderer.SetColorMode(output.ColorModeAlways)
md := markdown.NewMarkdownTable().SetColorMode(output.ColorModeAlways)RenderOptions (unified dispatch)
Section titled “RenderOptions (unified dispatch)”out, _ := output.RenderTable(data, output.FormatTable, output.RenderOptions{ ColorMode: output.ColorModeAuto,})Auto Detection
Section titled “Auto Detection”ColorModeAuto checks (in order):
- Writer TTY — Probes the writer’s own FD via
x/term.IsTerminal NO_COLOR— If set, disables color (industry standard)- CI environments —
CI,GITHUB_ACTIONS,GITLAB_CI,JENKINS_URL,BUILDKITE GO_OUTPUT_FORCE_COLOR/FORCE_COLOR— If set, forces color on
The only valid direction is TTY to plain text — a piped writer never gets ANSI codes.