Skip to main content

render_with_mode

Function render_with_mode 

Source
pub fn render_with_mode<T: Serialize>(
    template: &str,
    data: &T,
    theme: &Theme,
    output_mode: OutputMode,
    color_mode: ColorMode,
) -> Result<String, Error>
Expand description

Renders a template with explicit output mode and color mode control.

Use this when you need to force a specific color mode (light/dark), for example in tests or when honoring user preferences.

§Arguments

  • template - A minijinja template string
  • data - Any serializable data to pass to the template
  • theme - Theme definitions to use for the style filter
  • output_mode - Output mode: Auto, Term, Text, etc.
  • color_mode - Color mode: Light or Dark

§Example

use standout::{render_with_mode, Theme, OutputMode, ColorMode};
use console::Style;
use serde::Serialize;

#[derive(Serialize)]
struct Data { status: String }

let theme = Theme::new()
    .add_adaptive(
        "panel",
        Style::new(),
        Some(Style::new().black()),  // Light mode
        Some(Style::new().white()),  // Dark mode
    );

// Force dark mode rendering
let dark = render_with_mode(
    r#"[panel]{{ status }}[/panel]"#,
    &Data { status: "test".into() },
    &theme,
    OutputMode::Term,
    ColorMode::Dark,
).unwrap();

// Force light mode rendering
let light = render_with_mode(
    r#"[panel]{{ status }}[/panel]"#,
    &Data { status: "test".into() },
    &theme,
    OutputMode::Term,
    ColorMode::Light,
).unwrap();