Skip to main content

JsStyle

Struct JsStyle 

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

JavaScript-friendly wrapper for Style.

This provides a chainable API suitable for JavaScript usage, with methods that return a new JsStyle for method chaining.

Implementations§

Source§

impl JsStyle

Source

pub fn new() -> JsStyle

Create a new empty style.

Source

pub fn foreground(self, color: &str) -> JsStyle

Set the foreground color using a hex string (e.g., “#ff00ff”).

Source

pub fn background(self, color: &str) -> JsStyle

Set the background color using a hex string (e.g., “#1a1a1a”).

Source

pub fn bold(self) -> JsStyle

Enable bold text.

Source

pub fn italic(self) -> JsStyle

Enable italic text.

Source

pub fn underline(self) -> JsStyle

Enable underlined text.

Source

pub fn strikethrough(self) -> JsStyle

Enable strikethrough text.

Source

pub fn faint(self) -> JsStyle

Enable faint/dim text.

Source

pub fn reverse(self) -> JsStyle

Enable reverse video (swap foreground and background).

Source

pub fn padding_all(self, value: u16) -> JsStyle

Set padding on all sides.

Can be called with:

  • 1 argument: all sides
  • 2 arguments: vertical, horizontal
  • 4 arguments: top, right, bottom, left
Source

pub fn padding_vh(self, vertical: u16, horizontal: u16) -> JsStyle

Set padding with vertical and horizontal values.

Source

pub fn padding(self, top: u16, right: u16, bottom: u16, left: u16) -> JsStyle

Set padding for all four sides individually.

Source

pub fn margin_all(self, value: u16) -> JsStyle

Set margin on all sides.

Source

pub fn margin_vh(self, vertical: u16, horizontal: u16) -> JsStyle

Set margin with vertical and horizontal values.

Source

pub fn margin(self, top: u16, right: u16, bottom: u16, left: u16) -> JsStyle

Set margin for all four sides individually.

Source

pub fn width(self, w: u16) -> JsStyle

Set the width of the styled content.

Source

pub fn height(self, h: u16) -> JsStyle

Set the height of the styled content.

Source

pub fn border_style(self, style: &str) -> JsStyle

Set the border style.

Available styles: “normal”, “rounded”, “thick”, “double”, “hidden”, “ascii”

Source

pub fn border_all(self) -> JsStyle

Enable border on all sides.

Source

pub fn border_top(self) -> JsStyle

Enable border on top.

Source

pub fn border_bottom(self) -> JsStyle

Enable border on bottom.

Source

pub fn border_left(self) -> JsStyle

Enable border on left.

Source

pub fn border_right(self) -> JsStyle

Enable border on right.

Source

pub fn align_horizontal(self, value: f64) -> JsStyle

Set horizontal alignment.

Values: 0.0 = left, 0.5 = center, 1.0 = right

Source

pub fn align_vertical(self, value: f64) -> JsStyle

Set vertical alignment.

Values: 0.0 = top, 0.5 = center, 1.0 = bottom

Source

pub fn align_left(self) -> JsStyle

Align content to the left.

Source

pub fn align_center(self) -> JsStyle

Align content to the center.

Source

pub fn align_right(self) -> JsStyle

Align content to the right.

Source

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

Render content with this style as HTML.

Returns an HTML string with inline styles or CSS classes.

Source

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

Render content with this style as ANSI escape sequences.

This is useful for terminal-like displays in web applications.

Source

pub fn copy(&self) -> JsStyle

Copy this style.

Creates a new style with the same properties.

Trait Implementations§

Source§

impl Clone for JsStyle

Source§

fn clone(&self) -> JsStyle

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for JsStyle

Source§

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

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

impl Default for JsStyle

Source§

fn default() -> JsStyle

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

impl FromWasmAbi for JsStyle

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> JsStyle

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for JsStyle

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for JsStyle

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<JsStyle>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi( js: <JsStyle as LongRefFromWasmAbi>::Abi, ) -> <JsStyle as LongRefFromWasmAbi>::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for JsStyle

Source§

fn is_none(abi: &<JsStyle as FromWasmAbi>::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for JsStyle

Source§

fn none() -> <JsStyle as IntoWasmAbi>::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for JsStyle

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<JsStyle>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi( js: <JsStyle as RefFromWasmAbi>::Abi, ) -> <JsStyle as RefFromWasmAbi>::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for JsStyle

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<JsStyle>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi( js: <JsStyle as RefMutFromWasmAbi>::Abi, ) -> <JsStyle as RefMutFromWasmAbi>::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for JsStyle

Source§

fn try_from_js_value(value: JsValue) -> Result<JsStyle, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<JsStyle>

Performs the conversion.
Source§

impl VectorFromWasmAbi for JsStyle

Source§

impl VectorIntoWasmAbi for JsStyle

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> Instrument for T

Source§

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

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

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> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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