Style

Struct Style 

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

A style definition for rendering terminal content.

Style uses a builder pattern for easy chaining:

use lacquer::{Style, Border, Position, Color};

let style = Style::new()
    .padding(1, 2)
    .margin(0, 1)
    .border(Border::Rounded)
    .foreground(Color::from_hex("#F97316"))
    .background(Color::from_hex("#0A0A0A"))
    .bold()
    .width(40)
    .align(Position::Center);

Implementations§

Source§

impl Style

Source

pub const fn new() -> Self

Create a new empty style.

Source

pub const fn padding_all(self, padding: u16) -> Self

Set uniform padding on all sides.

Source

pub const fn padding(self, vertical: u16, horizontal: u16) -> Self

Set vertical and horizontal padding.

Source

pub const fn padding_sides( self, top: u16, right: u16, bottom: u16, left: u16, ) -> Self

Set padding for each side individually.

Source

pub const fn padding_top(self, padding: u16) -> Self

Set top padding.

Source

pub const fn padding_right(self, padding: u16) -> Self

Set right padding.

Source

pub const fn padding_bottom(self, padding: u16) -> Self

Set bottom padding.

Source

pub const fn padding_left(self, padding: u16) -> Self

Set left padding.

Source

pub const fn margin_all(self, margin: u16) -> Self

Set uniform margin on all sides.

Source

pub const fn margin(self, vertical: u16, horizontal: u16) -> Self

Set vertical and horizontal margin.

Source

pub const fn margin_sides( self, top: u16, right: u16, bottom: u16, left: u16, ) -> Self

Set margin for each side individually.

Source

pub const fn width(self, width: u16) -> Self

Set fixed width.

Source

pub const fn height(self, height: u16) -> Self

Set fixed height.

Source

pub const fn max_width(self, max: u16) -> Self

Set maximum width.

Source

pub const fn max_height(self, max: u16) -> Self

Set maximum height.

Source

pub const fn border(self, border: Border) -> Self

Set border style.

Source

pub fn border_foreground(self, color: Color) -> Self

Set uniform border color.

Source

pub fn border_foreground_hex(self, hex: &str) -> Self

Set border color from a hex string.

Source

pub fn foreground(self, color: Color) -> Self

Set foreground (text) color.

Accepts a Color, hex string, or RGB values.

use lacquer::{Style, Color};

let s1 = Style::new().foreground(Color::Red);
let s2 = Style::new().foreground(Color::from_hex("#F97316"));
let s3 = Style::new().foreground(Color::rgb(249, 115, 22));
Source

pub fn foreground_hex(self, hex: &str) -> Self

Set foreground color from a hex string.

Source

pub fn background(self, color: Color) -> Self

Set background color.

Source

pub fn background_hex(self, hex: &str) -> Self

Set background color from a hex string.

Source

pub const fn bold(self) -> Self

Enable bold text.

Source

pub const fn italic(self) -> Self

Enable italic text.

Source

pub const fn underline(self) -> Self

Enable underlined text.

Source

pub const fn strikethrough(self) -> Self

Enable strikethrough text.

Source

pub const fn dim(self) -> Self

Enable dim/faint text.

Source

pub const fn reverse(self) -> Self

Enable reverse video (swap fg/bg).

Source

pub const fn align(self, position: Position) -> Self

Set horizontal alignment.

Source

pub const fn vertical_align(self, position: Position) -> Self

Set vertical alignment.

Source

pub const fn inline(self) -> Self

Enable inline mode (no block wrapping).

Source

pub fn render(&self, content: &str) -> String

Render content with this style applied.

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.