pub struct Rule { /* private fields */ }Expand description
A horizontal divider line, optionally labelled with a title.
§Examples
use sparcli::{Renderable, Rule};
let out = Rule::with_title("Settings").render(30);
assert!(out.plain().contains("Settings"));Implementations§
Source§impl Rule
impl Rule
Sourcepub fn with_title(title: impl Into<Text>) -> Self
pub fn with_title(title: impl Into<Text>) -> Self
Creates a rule with an embedded title.
Examples found in repository?
examples/output_gallery.rs (line 35)
33fn section(title: &str) -> Result<()> {
34 println!();
35 Rule::with_title(title).align(Align::Left).print()?;
36 println!();
37 Ok(())
38}
39
40/// Styled spans, attributes, an OSC-8 hyperlink and optional markup.
41fn styled_text() -> Result<()> {
42 Rule::with_title("sparcli output gallery").print()?;
43 println!();
44 Rendered::new(vec![Line::new(vec![
45 Span::styled("bold ", Style::new().bold()),
46 Span::styled("dim ", Style::new().dim()),
47 Span::styled("italic ", Style::new().italic()),
48 Span::styled("red ", Style::new().fg(Color::Red)),
49 Span::styled("on-blue ", Style::new().bg(Color::Blue)),
50 Span::raw("link: "),
51 Span::raw("sparcli").link("https://example.com/sparcli"),
52 ])])
53 .print()?;
54
55 #[cfg(feature = "markup")]
56 markup_println("[bold green]markup[/]: [#ff8800]orange[/] and `code`")?;
57 Ok(())
58}
59
60/// Rules in all three alignments.
61fn sections() -> Result<()> {
62 section("Rules")?;
63 Rule::with_title("left")
64 .align(Align::Left)
65 .border(BorderType::Single)
66 .print()?;
67 Rule::with_title("center").align(Align::Center).print()?;
68 Rule::with_title("right")
69 .align(Align::Right)
70 .border(BorderType::Thick)
71 .print()?;
72 Ok(())
73}More examples
Sourcepub fn border(self, border: BorderType) -> Self
pub fn border(self, border: BorderType) -> Self
Sets the line style (border type).
Examples found in repository?
More examples
examples/output_gallery.rs (line 65)
61fn sections() -> Result<()> {
62 section("Rules")?;
63 Rule::with_title("left")
64 .align(Align::Left)
65 .border(BorderType::Single)
66 .print()?;
67 Rule::with_title("center").align(Align::Center).print()?;
68 Rule::with_title("right")
69 .align(Align::Right)
70 .border(BorderType::Thick)
71 .print()?;
72 Ok(())
73}Sourcepub fn align(self, align: Align) -> Self
pub fn align(self, align: Align) -> Self
Sets the title alignment.
Examples found in repository?
examples/output_gallery.rs (line 35)
33fn section(title: &str) -> Result<()> {
34 println!();
35 Rule::with_title(title).align(Align::Left).print()?;
36 println!();
37 Ok(())
38}
39
40/// Styled spans, attributes, an OSC-8 hyperlink and optional markup.
41fn styled_text() -> Result<()> {
42 Rule::with_title("sparcli output gallery").print()?;
43 println!();
44 Rendered::new(vec![Line::new(vec![
45 Span::styled("bold ", Style::new().bold()),
46 Span::styled("dim ", Style::new().dim()),
47 Span::styled("italic ", Style::new().italic()),
48 Span::styled("red ", Style::new().fg(Color::Red)),
49 Span::styled("on-blue ", Style::new().bg(Color::Blue)),
50 Span::raw("link: "),
51 Span::raw("sparcli").link("https://example.com/sparcli"),
52 ])])
53 .print()?;
54
55 #[cfg(feature = "markup")]
56 markup_println("[bold green]markup[/]: [#ff8800]orange[/] and `code`")?;
57 Ok(())
58}
59
60/// Rules in all three alignments.
61fn sections() -> Result<()> {
62 section("Rules")?;
63 Rule::with_title("left")
64 .align(Align::Left)
65 .border(BorderType::Single)
66 .print()?;
67 Rule::with_title("center").align(Align::Center).print()?;
68 Rule::with_title("right")
69 .align(Align::Right)
70 .border(BorderType::Thick)
71 .print()?;
72 Ok(())
73}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnsafeUnpin for Rule
impl UnwindSafe for Rule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more