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
impl Line
Sourcepub fn add_ansi_text<'a, T>(&mut self, input_line: T) -> &mut Line
pub fn add_ansi_text<'a, T>(&mut self, input_line: T) -> &mut Line
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
impl Line
Sourcepub fn from_cow(i: Cow<'_, str>) -> Line
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.
Sourcepub fn from_str(i: &str) -> Line
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.
Sourcepub fn from_string(i: String) -> Line
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.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns all the text in the line, without any styling information.
Sourcepub fn add_text<'a, T>(&mut self, i: T) -> &mut Line
pub fn add_text<'a, T>(&mut self, i: T) -> &mut Line
Adds additional text to the Line
using the currently-active
Style
and Color
s..
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
.
Sourcepub fn set_style(&mut self, nu: Style) -> &mut Line
pub fn set_style(&mut self, nu: Style) -> &mut Line
Change the active Style
to exactly that given.
Sourcepub fn toggle_style(&mut self, nu: Style) -> &mut Line
pub fn toggle_style(&mut self, nu: Style) -> &mut Line
Toggle every given Style
.
Sourcepub fn activate_style(&mut self, nu: Style) -> &mut Line
pub fn activate_style(&mut self, nu: Style) -> &mut Line
Activate the given Style
s, leaving any already-active Style
s
active.
Sourcepub fn deactivate_style(&mut self, nu: Style) -> &mut Line
pub fn deactivate_style(&mut self, nu: Style) -> &mut Line
Deactivate the given Style
s, without touching any unmentioned
Style
s that were already active.
Sourcepub fn clear_style(&mut self) -> &mut Line
pub fn clear_style(&mut self) -> &mut Line
Deactivate all Style
s. Same as calling
set_style(Style::PLAIN)
.
Sourcepub fn get_colors(&self) -> (Option<Color>, Option<Color>)
pub fn get_colors(&self) -> (Option<Color>, Option<Color>)
Gets the current Color
s, both foreground and background.
Sourcepub fn set_colors(&mut self, fg: Option<Color>, bg: Option<Color>) -> &mut Line
pub fn set_colors(&mut self, fg: Option<Color>, bg: Option<Color>) -> &mut Line
Sets both the foreground and background Color
.
Sourcepub fn chars(&self) -> LineCharIterator<'_> ⓘ
pub fn chars(&self) -> LineCharIterator<'_> ⓘ
Sourcepub fn reset_and_break(&mut self)
pub fn reset_and_break(&mut self)
Sourcepub fn append_line(&mut self, other: &Line)
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.
Sourcepub fn wrap_to_width(&mut self, width: usize)
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.