pub struct TemplateOptions {
pub width: usize,
pub line_height: Option<f64>,
pub advance_width: Option<f64>,
pub palette: Palette,
pub additional_styles: String,
pub font_family: String,
pub window_frame: bool,
pub scroll: Option<ScrollOptions>,
pub wrap: Option<WrapOptions>,
pub line_numbers: Option<LineNumbers>,
pub font_embedder: Option<Box<dyn FontEmbedder<Error = Box<dyn Error + Send + Sync>>>>,
}svg only.Expand description
Configurable options of a Template.
§Serialization
Options can be deserialized from serde-supported encoding formats, such as TOML. This is used
in the CLI app to read options from a file:
let options_toml = r#"
width = 900
window_frame = true
line_numbers = 'continuous'
wrap.hard_break_at = 100
scroll = { max_height = 300, pixels_per_scroll = 18, interval = 1.5 }
[palette.colors]
black = '#3c3836'
red = '#b85651'
green = '#8f9a52'
yellow = '#c18f41'
blue = '#68948a'
magenta = '#ab6c7d'
cyan = '#72966c'
white = '#a89984'
[palette.intense_colors]
black = '#5a524c'
red = '#b85651'
green = '#a9b665'
yellow = '#d8a657'
blue = '#7daea3'
magenta = '#d3869b'
cyan = '#89b482'
white = '#ddc7a1'
"#;
let options: TemplateOptions = toml::from_str(options_toml)?;
assert_eq!(options.width, 900);
assert_matches!(options.wrap, Some(WrapOptions::HardBreakAt(100)));
assert_eq!(
options.palette.colors.green,
RgbColor(0x8f, 0x9a, 0x52)
);Fields§
§width: usizeWidth of the rendered terminal window in pixels. Excludes the line numbers width if line
numbering is enabled. The default value is 720.
line_height: Option<f64>Line height relative to the font size. If not specified, will be taken from font metrics (if a font is embedded), or set to 1.2 otherwise.
advance_width: Option<f64>Advance width of a font relative to the font size (i.e., in em units). If not specified, will be taken from font metrics (if a font is embedded), or set to 8px (~0.57em) otherwise.
For now, advance width is only applied to the pure SVG template.
palette: PalettePalette of terminal colors. The default value of Palette is used by default.
additional_styles: StringCSS instructions to add at the beginning of the SVG <style> tag. This is mostly useful
to import fonts in conjunction with font_family.
The value is not validated in any way, so supplying invalid CSS instructions can lead to broken SVG rendering.
font_family: StringFont family specification in the CSS format. Should be monospace.
window_frame: boolIndicates whether to display a window frame around the shell. Default value is false.
scroll: Option<ScrollOptions>Options for the scroll animation. If set to None (which is the default),
no scrolling will be enabled, and the height of the generated image is not limited.
wrap: Option<WrapOptions>Text wrapping options. The default value of WrapOptions is used by default.
line_numbers: Option<LineNumbers>Line numbering options.
font_embedder: Option<Box<dyn FontEmbedder<Error = Box<dyn Error + Send + Sync>>>>Font embedder that will embed the font into the SVG file via @font-face CSS.
This guarantees that the SVG will look identical on all platforms.
Implementations§
Source§impl TemplateOptions
impl TemplateOptions
Sourcepub fn with_font_embedder(self, embedder: impl FontEmbedder) -> Self
pub fn with_font_embedder(self, embedder: impl FontEmbedder) -> Self
Sets the font embedder to be used.
Sourcepub fn with_font_subsetting(self, options: FontSubsetter) -> Self
Available on crate feature font-subset only.
pub fn with_font_subsetting(self, options: FontSubsetter) -> Self
font-subset only.Sets the standard font embedder / subsetter.
Sourcepub fn render_data<'s>(
&'s self,
transcript: &'s Transcript,
) -> Result<HandlebarsData<'s>, TermError>
pub fn render_data<'s>( &'s self, transcript: &'s Transcript, ) -> Result<HandlebarsData<'s>, TermError>
Generates data for rendering.
§Errors
Returns an error if output cannot be rendered to HTML (e.g., it contains invalid SGR sequences).
Trait Implementations§
Source§impl Debug for TemplateOptions
impl Debug for TemplateOptions
Source§impl Default for TemplateOptions
impl Default for TemplateOptions
Source§impl<'de> Deserialize<'de> for TemplateOptions
impl<'de> Deserialize<'de> for TemplateOptions
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for TemplateOptions
impl !RefUnwindSafe for TemplateOptions
impl Send for TemplateOptions
impl Sync for TemplateOptions
impl Unpin for TemplateOptions
impl !UnwindSafe for TemplateOptions
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);