Skip to content

feat(layout-text)!: replace no_color with color and stream-aware color_for - #346

Closed
tisonkun wants to merge 1 commit into
mainfrom
feat/text-layout-color-for
Closed

tisonkun wants to merge 1 commit into
mainfrom
feat/text-layout-color-for

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Change TextLayout::new() (and Default) in logforth-layout-text to omit ANSI severity coloring by default, and replace TextLayout::no_color with deterministic TextLayout::color(bool) and stream-aware TextLayout::color_for(&impl std::io::IsTerminal).
  • Resolve default TextLayout coloring in logforth::starter_log::{stdout, stderr, testing} at build time against the target stream (stdout for stdout(), stderr for stderr() and testing()).
  • Add unit and black-box child-process integration coverage for NO_COLOR, CLICOLOR_FORCE, terminal detection, palette ordering, and piped starter_log presets, and update documentation, examples, and CHANGELOG.md.

Design Notes

  • Sink-bound build-time resolution (color_for(&stream)) instead of lazy Layout state or a ColorMode enum: Layout::format writes into a caller-supplied Vec<u8> with no knowledge of the destination descriptor and may be shared across dispatches via Arc. Resolving color once against an explicit &impl io::IsTerminal keeps Layout::format pure and allocation/syscall-free, leaves logforth-core unchanged with zero dependencies, prevents probing stdout when writing to stderr (or vice versa), and maps cleanly from CLI enums (Always => .color(true), Never => .color(false), Auto => .color_for(&stream)) without introducing another ColorChoice type or conflicting with LogStarter::layout.
  • Safe uncolored default and minimal environment rules: Defaulting TextLayout::new() to color(false) prevents accidental ANSI sequences in File or Syslog sinks while starter_log remains colored on interactive terminals. color_for uses std only (NO_COLOR non-empty disables > CLICOLOR_FORCE non-empty and != "0" enables > stream.is_terminal()), omitting legacy CLICOLOR and TERM heuristics.

…r_for

`TextLayout` previously emitted ANSI severity colors by default, while `starter_log` constructed `TextLayout::default()` unconditionally. Redirecting `starter_log` output to files or pipes (or setting `NO_COLOR`) emitted raw ANSI escape sequences, and attaching `TextLayout::new()` to file or buffer sinks required remembering `.no_color()`.

Change `TextLayout::new()` (and `Default`) to omit ANSI colors by default, replace `TextLayout::no_color` with `TextLayout::color(bool)` and `TextLayout::color_for(&impl io::IsTerminal)` (evaluating `NO_COLOR`, `CLICOLOR_FORCE`, and `stream.is_terminal()` once at construction time), and configure default `starter_log` layouts against their target standard stream (`stdout` for `stdout()`, `stderr` for `stderr()` and `testing()`).

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun closed this Dec 4, 2026
@tisonkun
tisonkun deleted the feat/text-layout-color-for branch December 4, 2026 05:41
@tisonkun
tisonkun restored the feat/text-layout-color-for branch December 4, 2026 05:42
@tisonkun tisonkun reopened this Dec 4, 2026
@tisonkun tisonkun closed this Dec 4, 2026
@tisonkun
tisonkun deleted the feat/text-layout-color-for branch December 4, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant