Skip to main content

CharWidthTable

Struct CharWidthTable 

Source
pub struct CharWidthTable {
    pub cjk: u8,
    pub emoji: u8,
    pub nerd_font: u8,
    pub terminal: TerminalType,
    /* private fields */
}
Expand description

Character width table with caching

Fields§

§cjk: u8

Width for CJK characters

§emoji: u8

Width for emoji

§nerd_font: u8

Width for nerd font icons

§terminal: TerminalType

Detected terminal type

Implementations§

Source§

impl CharWidthTable

Source

pub fn new() -> Self

Create a new width table with defaults

Source

pub fn detect() -> Self

Detect character widths from terminal environment

This detects the terminal type from environment variables and sets appropriate default widths for emoji, CJK, and nerd fonts.

Note: This is a heuristic based on known terminal behaviors. For precise width detection, some terminals support querying character widths via escape sequences, but this is not universally supported and may cause issues in some environments.

Source

pub fn for_terminal(terminal: TerminalType) -> Self

Create for a specific terminal type

Source

pub fn width(&self, ch: char) -> u8

Get width of a character

Source

pub fn set_override(&mut self, ch: char, width: u8)

Override width for specific character

Source

pub fn with_cjk(self, width: u8) -> Self

Set CJK width

Source

pub fn with_emoji(self, width: u8) -> Self

Set emoji width

Source

pub fn with_nerd_font(self, width: u8) -> Self

Set nerd font width

Trait Implementations§

Source§

impl Default for CharWidthTable

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.