Line

Struct 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 add_ansi_text<'a, T>(&mut self, input_line: T) -> &mut Line
where T: Into<Cow<'a, str>>,

Adds additional text to the Line, respecting a subset of ANSI escape sequences in the process.

We support only CSI SGR codes (escape followed by [ ending with m). All unsupported codes are passed through unchanged.

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.

Unlike the one from the FromStr trait, this function always succeeds.

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 Line
where 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 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 Line

Source§

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

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

impl Default for Line

Source§

fn default() -> Self

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

impl From<&str> for Line

Source§

fn from(val: &str) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(val: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Line

Source§

fn from(val: String) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Line

Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Line

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 StructuralPartialEq for Line

Auto Trait Implementations§

§

impl Freeze for Line

§

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 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.