1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OutputTemplate {
Auto,
Json,
Pseudo,
Js,
Yaml,
Text,
Code,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Style {
Strict,
Default,
Detailed,
}
#[derive(Clone, Debug)]
pub struct RenderConfig {
pub template: OutputTemplate,
pub indent_unit: String,
pub space: String,
// Newline sequence to use in final output (e.g., "\n" or "").
// Templates read this directly; no post-processing replacement.
pub newline: String,
// When true, arrays prefer tail rendering (omission marker at start).
pub prefer_tail_arrays: bool,
// Desired color mode for rendering. Parsed and resolved to
// `color_enabled`; templates receive color via the Out writer.
pub color_mode: ColorMode,
// Resolved color enablement after considering `color_mode` and stdout TTY.
pub color_enabled: bool,
// Output styling mode (controls omission annotations), orthogonal to template.
pub style: Style,
// When Some(n), and only a line budget is active, allow rendering up to
// `n` graphemes of a string prefix regardless of top-K string-part inclusion.
pub string_free_prefix_graphemes: Option<usize>,
// When true, the core render path emits a debug JSON of the final
// inclusion set to stderr before rendering. CLI sets this flag.
pub debug: bool,
// Optional hint for the primary source name (e.g., filename) when rendering
// a single logical input outside of filesets. Used by code-specific
// features such as syntax highlighting.
pub primary_source_name: Option<String>,
// When false, suppress fileset section headers and summary lines.
pub show_fileset_headers: bool,
// When true, render filesets as a directory tree with inline previews.
pub fileset_tree: bool,
// When true, fileset headers and summaries count toward line budgets.
pub count_fileset_headers_in_budgets: bool,
// Optional regex for highlighting grep matches during rendering (color modes only).
pub grep_highlight: Option<regex::Regex>,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ColorMode {
On,
Off,
Auto,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ColorStrategy {
None,
Syntax,
HighlightOnly,
}
impl RenderConfig {
/// Derive the effective color strategy for this render configuration.
/// Syntax colors apply when color is enabled and no grep highlighting is active.
/// Highlight-only applies when color is enabled and a grep highlight regex is present.
pub fn color_strategy(&self) -> ColorStrategy {
if !self.color_enabled {
ColorStrategy::None
} else if self.grep_highlight.is_some() {
ColorStrategy::HighlightOnly
} else {
ColorStrategy::Syntax
}
}
}
impl ColorMode {
// Returns whether coloring should be enabled given whether stdout is a TTY.
pub fn effective(self, stdout_is_terminal: bool) -> bool {
match self {
ColorMode::On => true,
ColorMode::Off => false,
ColorMode::Auto => stdout_is_terminal,
}
}
}