pub struct Styled {
pub text: String,
pub style: TextStyle,
}Expand description
Styled text — text content with one or more applied styles.
§Examples
use scriba::{TextStyle, Styled};
let styled = Styled::new("Important", TextStyle::Bold);
assert_eq!(styled.text, "Important");
assert_eq!(styled.style, TextStyle::Bold);Fields§
§text: StringThe text content.
style: TextStyleThe applied style.
Implementations§
Source§impl Styled
impl Styled
Sourcepub fn new(text: impl Into<String>, style: TextStyle) -> Self
pub fn new(text: impl Into<String>, style: TextStyle) -> Self
Create new styled text.
Examples found in repository?
examples/styling.rs (line 21)
13fn main() -> scriba::Result<()> {
14 // Text format — ANSI escape codes applied
15 println!("=== TEXT FORMAT (ANSI codes) ===\n");
16
17 let ui_text = Ui::new().with_format(Format::Text);
18
19 let output_text = Output::new()
20 .heading(1, "Text Styling Examples")
21 .styled_paragraph(Styled::new("This is bold text", TextStyle::Bold))
22 .styled_paragraph(Styled::new("This is italic text", TextStyle::Italic))
23 .styled_paragraph(Styled::new("This is bold and italic", TextStyle::BoldItalic))
24 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline))
25 .styled_paragraph(Styled::new("This is strikethrough", TextStyle::Strikethrough))
26 .styled_paragraph(Styled::new("This is dimmed/faded", TextStyle::Dim));
27
28 ui_text.print(&output_text)?;
29
30 // Markdown format — Markdown syntax applied
31 println!("\n=== MARKDOWN FORMAT ===\n");
32
33 let ui_md = Ui::new().with_format(Format::Markdown);
34
35 let output_md = Output::new()
36 .heading(1, "Text Styling in Markdown")
37 .styled_paragraph(Styled::new("This is bold", TextStyle::Bold))
38 .styled_paragraph(Styled::new("This is italic", TextStyle::Italic))
39 .styled_paragraph(Styled::new("This is bold italic", TextStyle::BoldItalic))
40 .styled_paragraph(Styled::new("This has strikethrough", TextStyle::Strikethrough))
41 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline));
42
43 ui_md.print(&output_md)?;
44
45 // Direct use of Styled API
46 println!("\n=== DIRECT API ===\n");
47
48 let bold_styled = Styled::new("Warning: check your config", TextStyle::Bold);
49 let italic_styled = Styled::new("Optional: skip if unneeded", TextStyle::Italic);
50 let dim_styled = Styled::new("Hint: use --verbose for more detail", TextStyle::Dim);
51
52 println!("ANSI:");
53 println!(" {}", bold_styled.render_ansi());
54 println!(" {}", italic_styled.render_ansi());
55 println!(" {}", dim_styled.render_ansi());
56
57 println!("\nMarkdown:");
58 println!(" {}", bold_styled.render_markdown());
59 println!(" {}", italic_styled.render_markdown());
60 println!(" {}", dim_styled.render_markdown());
61
62 Ok(())
63}Sourcepub fn render_ansi(&self) -> String
pub fn render_ansi(&self) -> String
Render styled text with ANSI codes (for Text format).
Examples found in repository?
examples/styling.rs (line 53)
13fn main() -> scriba::Result<()> {
14 // Text format — ANSI escape codes applied
15 println!("=== TEXT FORMAT (ANSI codes) ===\n");
16
17 let ui_text = Ui::new().with_format(Format::Text);
18
19 let output_text = Output::new()
20 .heading(1, "Text Styling Examples")
21 .styled_paragraph(Styled::new("This is bold text", TextStyle::Bold))
22 .styled_paragraph(Styled::new("This is italic text", TextStyle::Italic))
23 .styled_paragraph(Styled::new("This is bold and italic", TextStyle::BoldItalic))
24 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline))
25 .styled_paragraph(Styled::new("This is strikethrough", TextStyle::Strikethrough))
26 .styled_paragraph(Styled::new("This is dimmed/faded", TextStyle::Dim));
27
28 ui_text.print(&output_text)?;
29
30 // Markdown format — Markdown syntax applied
31 println!("\n=== MARKDOWN FORMAT ===\n");
32
33 let ui_md = Ui::new().with_format(Format::Markdown);
34
35 let output_md = Output::new()
36 .heading(1, "Text Styling in Markdown")
37 .styled_paragraph(Styled::new("This is bold", TextStyle::Bold))
38 .styled_paragraph(Styled::new("This is italic", TextStyle::Italic))
39 .styled_paragraph(Styled::new("This is bold italic", TextStyle::BoldItalic))
40 .styled_paragraph(Styled::new("This has strikethrough", TextStyle::Strikethrough))
41 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline));
42
43 ui_md.print(&output_md)?;
44
45 // Direct use of Styled API
46 println!("\n=== DIRECT API ===\n");
47
48 let bold_styled = Styled::new("Warning: check your config", TextStyle::Bold);
49 let italic_styled = Styled::new("Optional: skip if unneeded", TextStyle::Italic);
50 let dim_styled = Styled::new("Hint: use --verbose for more detail", TextStyle::Dim);
51
52 println!("ANSI:");
53 println!(" {}", bold_styled.render_ansi());
54 println!(" {}", italic_styled.render_ansi());
55 println!(" {}", dim_styled.render_ansi());
56
57 println!("\nMarkdown:");
58 println!(" {}", bold_styled.render_markdown());
59 println!(" {}", italic_styled.render_markdown());
60 println!(" {}", dim_styled.render_markdown());
61
62 Ok(())
63}Sourcepub fn render_markdown(&self) -> String
pub fn render_markdown(&self) -> String
Render styled text with Markdown syntax.
Examples found in repository?
examples/styling.rs (line 58)
13fn main() -> scriba::Result<()> {
14 // Text format — ANSI escape codes applied
15 println!("=== TEXT FORMAT (ANSI codes) ===\n");
16
17 let ui_text = Ui::new().with_format(Format::Text);
18
19 let output_text = Output::new()
20 .heading(1, "Text Styling Examples")
21 .styled_paragraph(Styled::new("This is bold text", TextStyle::Bold))
22 .styled_paragraph(Styled::new("This is italic text", TextStyle::Italic))
23 .styled_paragraph(Styled::new("This is bold and italic", TextStyle::BoldItalic))
24 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline))
25 .styled_paragraph(Styled::new("This is strikethrough", TextStyle::Strikethrough))
26 .styled_paragraph(Styled::new("This is dimmed/faded", TextStyle::Dim));
27
28 ui_text.print(&output_text)?;
29
30 // Markdown format — Markdown syntax applied
31 println!("\n=== MARKDOWN FORMAT ===\n");
32
33 let ui_md = Ui::new().with_format(Format::Markdown);
34
35 let output_md = Output::new()
36 .heading(1, "Text Styling in Markdown")
37 .styled_paragraph(Styled::new("This is bold", TextStyle::Bold))
38 .styled_paragraph(Styled::new("This is italic", TextStyle::Italic))
39 .styled_paragraph(Styled::new("This is bold italic", TextStyle::BoldItalic))
40 .styled_paragraph(Styled::new("This has strikethrough", TextStyle::Strikethrough))
41 .styled_paragraph(Styled::new("This is underlined", TextStyle::Underline));
42
43 ui_md.print(&output_md)?;
44
45 // Direct use of Styled API
46 println!("\n=== DIRECT API ===\n");
47
48 let bold_styled = Styled::new("Warning: check your config", TextStyle::Bold);
49 let italic_styled = Styled::new("Optional: skip if unneeded", TextStyle::Italic);
50 let dim_styled = Styled::new("Hint: use --verbose for more detail", TextStyle::Dim);
51
52 println!("ANSI:");
53 println!(" {}", bold_styled.render_ansi());
54 println!(" {}", italic_styled.render_ansi());
55 println!(" {}", dim_styled.render_ansi());
56
57 println!("\nMarkdown:");
58 println!(" {}", bold_styled.render_markdown());
59 println!(" {}", italic_styled.render_markdown());
60 println!(" {}", dim_styled.render_markdown());
61
62 Ok(())
63}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Styled
impl<'de> Deserialize<'de> for Styled
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Styled
impl StructuralPartialEq for Styled
Auto Trait Implementations§
impl Freeze for Styled
impl RefUnwindSafe for Styled
impl Send for Styled
impl Sync for Styled
impl Unpin for Styled
impl UnsafeUnpin for Styled
impl UnwindSafe for Styled
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