pub struct Title {
pub content: Text,
pub align: Align,
pub position: Position,
pub pad: u16,
}Expand description
A framed title, e.g. on a panel, rule or table.
When inset into a border, a left-aligned title reads as part of the frame
with one connecting glyph before it (┌─ Title ─), not a flush ┌ Title.
Fields§
§content: TextThe title content (rich text).
align: AlignHorizontal placement along the edge.
position: PositionWhich edge the title sits on.
pad: u16Spaces of padding on each side of the title text.
Implementations§
Source§impl Title
impl Title
Sourcepub fn new(content: impl Into<Text>) -> Self
pub fn new(content: impl Into<Text>) -> Self
Creates a left-aligned top title with single-space padding.
Examples found in repository?
More examples
examples/output_gallery.rs (line 95)
87fn panels() -> Result<()> {
88 section("Panels")?;
89 Panel::new("Rounded border (default).").print()?;
90 Panel::new("Double border.")
91 .border(BorderType::Double)
92 .print()?;
93 Panel::new("Centered, filled, fixed width.")
94 .border(BorderType::Thick)
95 .title(Title::new("Title"))
96 .subtitle(Title::new("subtitle"))
97 .content_align(Align::Center)
98 .fill(Style::new().bg(Color::Indexed(236)))
99 .width(40)
100 .print()?;
101 Ok(())
102}examples/prompt-readme.rs (line 43)
33fn hero(width: u16) -> Result<()> {
34 let theme = theme();
35 let body = Text::new(vec![
36 Line::raw("Interactive prompts - confirm · select · text · password ·"),
37 Line::raw("number · textarea · fuzzy · date."),
38 ]);
39 Panel::new(body)
40 .border(BorderType::Rounded)
41 .border_style(Style::new().fg(theme.accent))
42 .title(
43 Title::new(" sparcli · input widgets ")
44 .align(Align::Center)
45 .style(theme.title),
46 )
47 .content_align(Align::Center)
48 .width(width)
49 .print()
50}examples/output-readme.rs (line 53)
29fn hero() -> Result<()> {
30 let cyan = Style::new().fg(Color::Cyan).bold();
31 let on_magenta = Style::new().fg(Color::Black).bg(Color::Magenta).bold();
32 let yellow = Style::new().fg(Color::Yellow).bold();
33 let body = Text::new(vec![
34 Line::new(vec![
35 Span::raw("A native Rust library for "),
36 Span::styled("styled terminal output", cyan),
37 Span::raw(" and "),
38 Span::styled("input", on_magenta),
39 Span::raw(" - panels, tables, trees, lists,"),
40 ]),
41 Line::new(vec![
42 Span::raw("key-value pairs, badges, rules, "),
43 Span::styled("columns", cyan),
44 Span::raw(" and progress bars, with Rich-compatible "),
45 Span::styled("[markup]", yellow),
46 Span::raw("."),
47 ]),
48 ]);
49 Panel::new(body)
50 .border(BorderType::Rounded)
51 .border_style(Style::new().fg(Color::Cyan))
52 .title(
53 Title::new(" sparcli ")
54 .align(Align::Center)
55 .style(Style::new().fg(Color::Cyan).bold()),
56 )
57 .content_align(Align::Center)
58 .width(96)
59 .print()
60}Sourcepub fn align(self, align: Align) -> Self
pub fn align(self, align: Align) -> Self
Sets the horizontal alignment.
Examples found in repository?
examples/prompt-readme.rs (line 44)
33fn hero(width: u16) -> Result<()> {
34 let theme = theme();
35 let body = Text::new(vec![
36 Line::raw("Interactive prompts - confirm · select · text · password ·"),
37 Line::raw("number · textarea · fuzzy · date."),
38 ]);
39 Panel::new(body)
40 .border(BorderType::Rounded)
41 .border_style(Style::new().fg(theme.accent))
42 .title(
43 Title::new(" sparcli · input widgets ")
44 .align(Align::Center)
45 .style(theme.title),
46 )
47 .content_align(Align::Center)
48 .width(width)
49 .print()
50}More examples
examples/output-readme.rs (line 54)
29fn hero() -> Result<()> {
30 let cyan = Style::new().fg(Color::Cyan).bold();
31 let on_magenta = Style::new().fg(Color::Black).bg(Color::Magenta).bold();
32 let yellow = Style::new().fg(Color::Yellow).bold();
33 let body = Text::new(vec![
34 Line::new(vec![
35 Span::raw("A native Rust library for "),
36 Span::styled("styled terminal output", cyan),
37 Span::raw(" and "),
38 Span::styled("input", on_magenta),
39 Span::raw(" - panels, tables, trees, lists,"),
40 ]),
41 Line::new(vec![
42 Span::raw("key-value pairs, badges, rules, "),
43 Span::styled("columns", cyan),
44 Span::raw(" and progress bars, with Rich-compatible "),
45 Span::styled("[markup]", yellow),
46 Span::raw("."),
47 ]),
48 ]);
49 Panel::new(body)
50 .border(BorderType::Rounded)
51 .border_style(Style::new().fg(Color::Cyan))
52 .title(
53 Title::new(" sparcli ")
54 .align(Align::Center)
55 .style(Style::new().fg(Color::Cyan).bold()),
56 )
57 .content_align(Align::Center)
58 .width(96)
59 .print()
60}Sourcepub fn style(self, style: Style) -> Self
pub fn style(self, style: Style) -> Self
Applies a style to every span of the title.
Examples found in repository?
examples/prompt-readme.rs (line 45)
33fn hero(width: u16) -> Result<()> {
34 let theme = theme();
35 let body = Text::new(vec![
36 Line::raw("Interactive prompts - confirm · select · text · password ·"),
37 Line::raw("number · textarea · fuzzy · date."),
38 ]);
39 Panel::new(body)
40 .border(BorderType::Rounded)
41 .border_style(Style::new().fg(theme.accent))
42 .title(
43 Title::new(" sparcli · input widgets ")
44 .align(Align::Center)
45 .style(theme.title),
46 )
47 .content_align(Align::Center)
48 .width(width)
49 .print()
50}More examples
examples/output-readme.rs (line 55)
29fn hero() -> Result<()> {
30 let cyan = Style::new().fg(Color::Cyan).bold();
31 let on_magenta = Style::new().fg(Color::Black).bg(Color::Magenta).bold();
32 let yellow = Style::new().fg(Color::Yellow).bold();
33 let body = Text::new(vec![
34 Line::new(vec![
35 Span::raw("A native Rust library for "),
36 Span::styled("styled terminal output", cyan),
37 Span::raw(" and "),
38 Span::styled("input", on_magenta),
39 Span::raw(" - panels, tables, trees, lists,"),
40 ]),
41 Line::new(vec![
42 Span::raw("key-value pairs, badges, rules, "),
43 Span::styled("columns", cyan),
44 Span::raw(" and progress bars, with Rich-compatible "),
45 Span::styled("[markup]", yellow),
46 Span::raw("."),
47 ]),
48 ]);
49 Panel::new(body)
50 .border(BorderType::Rounded)
51 .border_style(Style::new().fg(Color::Cyan))
52 .title(
53 Title::new(" sparcli ")
54 .align(Align::Center)
55 .style(Style::new().fg(Color::Cyan).bold()),
56 )
57 .content_align(Align::Center)
58 .width(96)
59 .print()
60}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Title
impl RefUnwindSafe for Title
impl Send for Title
impl Sync for Title
impl Unpin for Title
impl UnsafeUnpin for Title
impl UnwindSafe for Title
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