Struct liso::Line

source ·
pub struct Line { /* private fields */ }
Expand description

This is a line of text, with optional styling information, ready for display. The liso! macro is extremely convenient for building these. You can also pass a String, &str, or Cow<str> to most Liso functions that accept a Line.

Implementations§

source§

impl Line

source

pub fn new() -> Line

Creates a new, empty line.

source

pub fn from_cow(i: Cow<'_, str>) -> Line

Creates a new line, containing the given, unstyled, text. Creates a new copy iff the passed Cow is borrowed or contains control characters.

source

pub fn from_str(i: &str) -> Line

Creates a new line, containing the given, unstyled, text. Always copies the passed string.

source

pub fn from_string(i: String) -> Line

Creates a new line, containing the given, unstyled, text. Creates a new copy iff the passed String contains control characters.

source

pub fn as_str(&self) -> &str

Returns all the text in the line, without any styling information.

source

pub fn add_text<'a, T>(&mut self, i: T) -> &mut Linewhere T: Into<Cow<'a, str>>,

Adds additional text to the Line using the currently-active Style and Colors..

You may pass a String, &str, or Cow<str> here, but not a Line. If you want to append styled text, see append_line. If you want to append the text from a Line but discard its style information, call as_str on that Line.

source

pub fn get_style(&self) -> Style

Returns the currently active Style.

source

pub fn set_style(&mut self, nu: Style) -> &mut Line

Change the active Style to exactly that given.

source

pub fn toggle_style(&mut self, nu: Style) -> &mut Line

Toggle every given Style.

source

pub fn activate_style(&mut self, nu: Style) -> &mut Line

Activate the given Styles, leaving any already-active Styles active.

source

pub fn deactivate_style(&mut self, nu: Style) -> &mut Line

Deactivate the given Styles, without touching any unmentioned Styles that were already active.

source

pub fn clear_style(&mut self) -> &mut Line

Deactivate all Styles. Same as calling set_style(Style::PLAIN).

source

pub fn get_colors(&self) -> (Option<Color>, Option<Color>)

Gets the current Colors, both foreground and background.

source

pub fn set_fg_color(&mut self, nu: Option<Color>) -> &mut Line

Sets the foreground Color.

source

pub fn set_bg_color(&mut self, nu: Option<Color>) -> &mut Line

Sets the background Color.

source

pub fn set_colors(&mut self, fg: Option<Color>, bg: Option<Color>) -> &mut Line

Sets both the foreground and background Color.

source

pub fn reset_all(&mut self) -> &mut Line

Reset ALL Style and Color information to default. Equivalent to:

line.set_style(Style::PLAIN).set_colors(None, None);

(In fact, that is the body of this function.)

source

pub fn is_empty(&self) -> bool

Returns true if this line contains no text. (It may yet contain some Style or Color information.)

source

pub fn len(&self) -> usize

Returns the number of BYTES of text this line contains.

source

pub fn chars(&self) -> LineCharIterator<'_>

Iterate over chars of the line, including Style and Color information, one char at a time.

The usual caveats about the difference between a char and a character apply. Unicode etc.

Yields: (byte_index, character, style, fgcolor, bgcolor)

source

pub fn reset_and_break(&mut self)

Add a linebreak and then clear Style and Colors.

Equivalent to:

line.add_text("\n");
line.set_style(Style::empty());
line.set_colors(None, None);

(In fact, that is the body of this function.)

source

pub fn append_line(&mut self, other: &Line)

Append another Line to ourselves, including Style and Color information. You may want to reset_and_break first.

source

pub fn wrap_to_width(&mut self, width: usize)

Insert linebreaks as necessary to make it so that no line within this Line is wider than the given number of columns. Only available with the wrap feature, which is enabled by default.

Rather than calling this method yourself, you definitely want to use the wrapln method instead of the println method. That way, Liso will automatically wrap the line of text to the correct width for the user’s terminal.

Trait Implementations§

source§

impl Clone for Line

source§

fn clone(&self) -> Line

Returns a copy 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 Line

source§

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

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

impl Into<Line> for &str

source§

fn into(self) -> Line

Converts this type into the (usually inferred) input type.
source§

impl Into<Line> for Cow<'_, str>

source§

fn into(self) -> Line

Converts this type into the (usually inferred) input type.
source§

impl Into<Line> for String

source§

fn into(self) -> Line

Converts this type into the (usually inferred) input type.
source§

impl PartialEq<Line> for Line

source§

fn eq(&self, other: &Line) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Line

source§

impl StructuralEq for Line

source§

impl StructuralPartialEq for Line

Auto Trait Implementations§

§

impl RefUnwindSafe for Line

§

impl Send for Line

§

impl Sync for Line

§

impl Unpin for Line

§

impl UnwindSafe for Line

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.