Repository navigation
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TextLayout::new()(andDefault) inlogforth-layout-textto omit ANSI severity coloring by default, and replaceTextLayout::no_colorwith deterministicTextLayout::color(bool)and stream-awareTextLayout::color_for(&impl std::io::IsTerminal).TextLayoutcoloring inlogforth::starter_log::{stdout, stderr, testing}at build time against the target stream (stdoutforstdout(),stderrforstderr()andtesting()).NO_COLOR,CLICOLOR_FORCE, terminal detection, palette ordering, and pipedstarter_logpresets, and update documentation, examples, andCHANGELOG.md.Design Notes
color_for(&stream)) instead of lazyLayoutstate or aColorModeenum:Layout::formatwrites into a caller-suppliedVec<u8>with no knowledge of the destination descriptor and may be shared across dispatches viaArc. Resolving color once against an explicit&impl io::IsTerminalkeepsLayout::formatpure and allocation/syscall-free, leaveslogforth-coreunchanged with zero dependencies, prevents probingstdoutwhen writing tostderr(or vice versa), and maps cleanly from CLI enums (Always => .color(true),Never => .color(false),Auto => .color_for(&stream)) without introducing anotherColorChoicetype or conflicting withLogStarter::layout.TextLayout::new()tocolor(false)prevents accidental ANSI sequences inFileorSyslogsinks whilestarter_logremains colored on interactive terminals.color_forusesstdonly (NO_COLORnon-empty disables >CLICOLOR_FORCEnon-empty and!= "0"enables >stream.is_terminal()), omitting legacyCLICOLORandTERMheuristics.