TemplateOptions

Struct TemplateOptions 

Source
pub struct TemplateOptions {
Show 13 fields pub width: NonZeroUsize, pub line_height: Option<f64>, pub advance_width: Option<f64>, pub palette: Palette, pub dim_opacity: f64, pub blink: BlinkOptions, pub additional_styles: String, pub font_family: String, pub window: Option<WindowOptions>, pub scroll: Option<ScrollOptions>, pub wrap: Option<WrapOptions>, pub line_numbers: Option<LineNumberingOptions>, pub font_embedder: Option<Box<dyn FontEmbedder<Error = Box<dyn Error + Send + Sync>>>>,
}
Available on crate feature 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.scope = 'continuous'
wrap.hard_break_at.chars = 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.get(), 900);
assert_matches!(
    options.wrap,
    Some(WrapOptions::HardBreakAt { chars, .. }) if chars.get() == 100
);
assert_eq!(
    options.palette.colors.green,
    anstyle::RgbColor(0x8f, 0x9a, 0x52)
);

Fields§

§width: NonZeroUsize

Width 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: Palette

Palette of terminal colors. The default value of Palette is used by default.

§dim_opacity: f64

Opacity of dimmed text. The default value is 0.7.

§blink: BlinkOptions

Blink options.

§additional_styles: String

CSS 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: String

Font family specification in the CSS format. Should be monospace.

§window: Option<WindowOptions>

Window options.

§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<LineNumberingOptions>

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

Source

pub fn with_font_embedder(self, embedder: impl FontEmbedder) -> Self

Sets the font embedder to be used.

Source

pub fn with_font_subsetting(self, options: FontSubsetter) -> Self

Available on crate feature font-subset only.
Source

pub fn validated(self) -> Result<ValidTemplateOptions>

Validates these options. This is equivalent to using TryInto.

§Errors

Returns an error if options are invalid.

Trait Implementations§

Source§

impl Debug for TemplateOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TemplateOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TemplateOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TemplateOptions

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<TemplateOptions> for ValidTemplateOptions

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(options: TemplateOptions) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,