Skip to main content

Figlet

Struct Figlet 

Source
pub struct Figlet { /* private fields */ }
Expand description

A reusable renderer holding a parsed Font and resolved layout settings.

Cheap to clone; clone the Figlet across threads to render many banners concurrently with the same font configuration.

use rusty_figlet::{FigletBuilder, Font};

let figlet = FigletBuilder::new()
    .font(Font::Standard)
    .build()
    .expect("build");
let banner = figlet.render("Hi").expect("render");
assert!(banner.height() >= 1);

Implementations§

Source§

impl Figlet

Source

pub fn render(&self, text: &str) -> Result<Banner, FigletError>

Render text into a Banner.

The returned banner exposes a lazy line iterator (per FR-053): row buffers are precomputed once during render(), and Banner::lines yields one row per next() without copying the whole banner.

Source

pub fn from_tlf(path: impl AsRef<Path>) -> Result<Figlet, FigletError>

Available on crate feature tlf-parser only.

Load a .tlf font from disk and return a renderable Figlet.

Bounded per spec Edge Cases: zero-byte files, files larger than 8 MiB, and symlink loops are rejected before allocation.

Returns FigletError::InvalidTlfHeader when the magic prefix mismatches, FigletError::TlfParse for later parse failures. Gated by the tlf-parser Cargo leaf.

Source

pub fn from_tlf_bytes(bytes: &[u8]) -> Result<Figlet, FigletError>

Available on crate feature tlf-parser only.

Build a Figlet from raw .tlf bytes (no filesystem access).

Mirrors Figlet::from_tlf but skips the disk-bounded I/O checks. Bytes larger than 8 MiB still trigger FigletError::TlfParse. Gated by the tlf-parser Cargo leaf.

Source

pub fn color_depth(&self) -> ColorDepth

Cached color depth in use by this renderer (E012 US4 — AD-003).

Set at builder time via FigletBuilder::color_depth (or auto-detected via ColorDepth::detect when unset) and cached onto the renderer for the lifetime of this instance per FR-031.

The render path NEVER re-probes the terminal — invalidation is caller-driven only via Figlet::set_color_depth.

Source

pub fn set_color_depth(&mut self, depth: ColorDepth)

Invalidate the cached color depth (E012 US4 — AD-003 + FR-031).

Replaces the cached value; subsequent renders observe the new depth. Callers who wish to re-detect the terminal capability should pass ColorDepth::detect.

This is the only documented way to invalidate the cache — the render path itself never re-probes per FR-031. Calling this method does not allocate.

Trait Implementations§

Source§

impl Clone for Figlet

Source§

fn clone(&self) -> Figlet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Figlet

Source§

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

Formats the value using the given formatter. Read more

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.