Skip to main content

render

Function render 

Source
pub fn render<T: Serialize>(
    template: &str,
    data: &T,
    theme: &Theme,
) -> Result<String, Error>
Expand description

Renders a template with automatic terminal color detection.

This is the simplest way to render styled output. It automatically detects whether stdout supports colors and applies styles accordingly. Color mode (light/dark) is detected from OS settings.

§Arguments

  • template - A minijinja template string
  • data - Any serializable data to pass to the template
  • theme - Theme definitions to use for the style filter

§Example

use standout::{render, Theme};
use console::Style;
use serde::Serialize;

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

let theme = Theme::new().add("ok", Style::new().green());
let output = render(
    r#"[ok]{{ message }}[/ok]"#,
    &Data { message: "Success!".into() },
    &theme,
).unwrap();