Skip to main content

Title

Struct Title 

Source
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: Text

The title content (rich text).

§align: Align

Horizontal placement along the edge.

§position: Position

Which edge the title sits on.

§pad: u16

Spaces of padding on each side of the title text.

Implementations§

Source§

impl Title

Source

pub fn new(content: impl Into<Text>) -> Self

Creates a left-aligned top title with single-space padding.

Examples found in repository?
examples/output_dynamic.rs (line 62)
58fn live() -> Result<()> {
59    let mut live = Live::new();
60    for tick in 1..=8 {
61        let frame = Panel::new(format!("live tick {tick}"))
62            .title(Title::new("Live"))
63            .render(30);
64        live.update(&frame)?;
65        sleep(Duration::from_millis(120));
66    }
67    live.finish()
68}
More examples
Hide additional 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}
Source

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
Hide additional 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}
Source

pub fn position(self, position: Position) -> Self

Sets the edge the title sits on.

Source

pub fn pad(self, pad: u16) -> Self

Sets the padding on each side of the title text.

Source

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
Hide additional 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§

Source§

impl Clone for Title

Source§

fn clone(&self) -> Title

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Title

Source§

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

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

impl Default for Title

Source§

fn default() -> Title

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

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