facet_showcase/
output.rs

1//! Output mode detection and configuration.
2
3use std::env;
4
5/// Output mode for showcase rendering.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub enum OutputMode {
8    /// Terminal output with ANSI colors
9    #[default]
10    Terminal,
11    /// Markdown output with embedded HTML for Zola
12    ///
13    /// Headings are emitted as Markdown so Zola can build a table of contents.
14    /// Content blocks (code, errors, etc.) are emitted as HTML.
15    Markdown,
16}
17
18impl OutputMode {
19    /// Detect output mode from environment variable `FACET_SHOWCASE_OUTPUT`.
20    ///
21    /// Values:
22    /// - `markdown` or `MARKDOWN` → OutputMode::Markdown
23    /// - anything else (or unset) → OutputMode::Terminal
24    pub fn from_env() -> Self {
25        match env::var("FACET_SHOWCASE_OUTPUT").as_deref() {
26            Ok("markdown") | Ok("MARKDOWN") => OutputMode::Markdown,
27            _ => OutputMode::Terminal,
28        }
29    }
30
31    /// Check if this is terminal output mode.
32    pub fn is_terminal(self) -> bool {
33        self == OutputMode::Terminal
34    }
35
36    /// Check if this is Markdown output mode.
37    pub fn is_markdown(self) -> bool {
38        self == OutputMode::Markdown
39    }
40}