pub struct RenderContext<'a> {
pub output_mode: OutputMode,
pub terminal_width: Option<usize>,
pub theme: &'a Theme,
pub data: &'a Value,
pub extras: HashMap<String, String>,
}Expand description
Information available at render time for dynamic context providers.
This struct is passed to ContextProvider::provide to allow context objects
to be configured based on runtime conditions.
§Fields
output_mode: The current output mode (Term, Text, Json, etc.)terminal_width: Terminal width in columns, if knowntheme: The theme being used for renderingdata: The handler’s output data as a JSON valueextras: Additional string key-value pairs for extension
§Example
use standout::context::RenderContext;
use standout::{OutputMode, Theme};
let ctx = RenderContext {
output_mode: OutputMode::Term,
terminal_width: Some(120),
theme: &Theme::new(),
data: &serde_json::json!({"count": 42}),
extras: std::collections::HashMap::new(),
};
// Use context to configure a formatter
let width = ctx.terminal_width.unwrap_or(80);Fields§
§output_mode: OutputModeThe output mode for rendering (Term, Text, Json, etc.)
terminal_width: Option<usize>Terminal width in columns, if available.
This is None when:
- Output is not to a terminal (piped, redirected)
- Terminal width cannot be determined
- Running in a non-TTY environment
theme: &'a ThemeThe theme being used for rendering.
data: &'a ValueThe handler’s output data, serialized as JSON.
This allows context providers to inspect the data being rendered and adjust their behavior accordingly.
extras: HashMap<String, String>Additional string key-value pairs for extension.
This allows passing arbitrary metadata to context providers without modifying the struct definition.
Implementations§
Source§impl<'a> RenderContext<'a>
impl<'a> RenderContext<'a>
Sourcepub fn new(
output_mode: OutputMode,
terminal_width: Option<usize>,
theme: &'a Theme,
data: &'a Value,
) -> Self
pub fn new( output_mode: OutputMode, terminal_width: Option<usize>, theme: &'a Theme, data: &'a Value, ) -> Self
Creates a new render context with the given parameters.
Trait Implementations§
Source§impl<'a> Clone for RenderContext<'a>
impl<'a> Clone for RenderContext<'a>
Source§fn clone(&self) -> RenderContext<'a>
fn clone(&self) -> RenderContext<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for RenderContext<'a>
impl<'a> RefUnwindSafe for RenderContext<'a>
impl<'a> Send for RenderContext<'a>
impl<'a> Sync for RenderContext<'a>
impl<'a> Unpin for RenderContext<'a>
impl<'a> UnwindSafe for RenderContext<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more