headson/serialization/
types.rs

1#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2pub enum OutputTemplate {
3    Auto,
4    Json,
5    Pseudo,
6    Js,
7    Yaml,
8    Text,
9}
10
11#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12pub enum Style {
13    Strict,
14    Default,
15    Detailed,
16}
17
18#[derive(Clone, Debug, Eq, PartialEq)]
19pub struct RenderConfig {
20    pub template: OutputTemplate,
21    pub indent_unit: String,
22    pub space: String,
23    // Newline sequence to use in final output (e.g., "\n" or "").
24    // Templates read this directly; no post-processing replacement.
25    pub newline: String,
26    // When true, arrays prefer tail rendering (omission marker at start).
27    pub prefer_tail_arrays: bool,
28    // Desired color mode for rendering. Parsed and resolved to
29    // `color_enabled`; templates receive color via the Out writer.
30    pub color_mode: ColorMode,
31    // Resolved color enablement after considering `color_mode` and stdout TTY.
32    pub color_enabled: bool,
33    // Output styling mode (controls omission annotations), orthogonal to template.
34    pub style: Style,
35}
36
37#[derive(Copy, Clone, Debug, Eq, PartialEq)]
38pub enum ColorMode {
39    On,
40    Off,
41    Auto,
42}
43
44impl ColorMode {
45    // Returns whether coloring should be enabled given whether stdout is a TTY.
46    pub fn effective(self, stdout_is_terminal: bool) -> bool {
47        match self {
48            ColorMode::On => true,
49            ColorMode::Off => false,
50            ColorMode::Auto => stdout_is_terminal,
51        }
52    }
53}