pub struct Note { /* private fields */ }Expand description
A styled callout block for warnings, tips, and info messages.
The Note struct provides a way to display important messages
in a visually distinct box in the terminal. It supports various
kinds (info, warning, tip), custom icons, colors, boldness,
and different border styles.
§Examples
A basic information note:
use cliux::components::Note;
Note::new("This is an important piece of information.")
.kind("info")
.print();A warning note with a custom width and square borders:
use cliux::components::Note;
Note::new("Be cautious when proceeding with this action.")
.kind("warning")
.width(60)
.style("square")
.print();A tip with a custom icon and color:
use cliux::components::Note;
Note::new("Remember to save your work frequently!")
.icon("✨")
.color("magenta")
.bold(true)
.print();Implementations§
Source§impl Note
impl Note
Sourcepub fn new(text: &str) -> Self
pub fn new(text: &str) -> Self
Creates a new Note instance with the given text.
By default, the note will have “rounded” borders, a width of 50 characters, no specific icon, color, or boldness.
§Arguments
text- The main content string for the note.
§Returns
A new Note instance.
Examples found in repository?
3fn main() {
4 Note::new("Be careful with this setting.")
5 .kind("warning")
6 .style("rounded")
7 .width(40)
8 .print();
9
10 Note::new("Tip: You can use --force here.")
11 .kind("info")
12 .style("+")
13 .width(40)
14 .print();
15}Sourcepub fn kind(self, kind: &str) -> Self
pub fn kind(self, kind: &str) -> Self
Applies a predefined “kind” style to the note.
This method consumes self and returns a new Note instance,
allowing for method chaining. It sets a default icon, color,
and boldness based on the kind.
Supported kinds:
"info": Sets icon to “ℹ️”, color to blue."warning": Sets icon to “⚠️”, color to yellow, and text to bold."tip": Sets icon to “💡”, color to green.
If an unknown kind is provided, the note remains unchanged.
§Arguments
kind- A string slice representing the predefined style kind.
§Returns
The Note instance with the applied kind style.
Examples found in repository?
3fn main() {
4 Note::new("Be careful with this setting.")
5 .kind("warning")
6 .style("rounded")
7 .width(40)
8 .print();
9
10 Note::new("Tip: You can use --force here.")
11 .kind("info")
12 .style("+")
13 .width(40)
14 .print();
15}Sourcepub fn icon(self, icon: &str) -> Self
pub fn icon(self, icon: &str) -> Self
Sets a custom icon for the note.
This method consumes self and returns a new Note instance,
allowing for method chaining. This will override any icon set by kind().
§Arguments
icon- A string slice representing the custom icon (e.g., an emoji like “✨”).
§Returns
The Note instance with the updated icon.
Sourcepub fn color(self, color: &str) -> Self
pub fn color(self, color: &str) -> Self
Sets the foreground color of the note’s text and icon.
This method consumes self and returns a new Note instance,
allowing for method chaining. Supported colors include “red”, “green”,
“yellow”, “blue”, “magenta” (or “purple”), “cyan”, and “white”.
Color names are case-insensitive.
§Arguments
color- A string slice representing the desired color name.
§Returns
The Note instance with the updated color.
Sourcepub fn style(self, style: &str) -> Self
pub fn style(self, style: &str) -> Self
Sets the border style for the note.
This method consumes self and returns a new Note instance,
allowing for method chaining.
Supported styles:
"rounded"(default): Uses╭╮╰╯─│characters."square": Uses┌┐└┘─│characters."+": Uses++++--||characters for a simpler ASCII look.
If an unknown style is provided, it defaults to “square” borders.
§Arguments
style- A string slice representing the desired border style.
§Returns
The Note instance with the updated border style.
Examples found in repository?
3fn main() {
4 Note::new("Be careful with this setting.")
5 .kind("warning")
6 .style("rounded")
7 .width(40)
8 .print();
9
10 Note::new("Tip: You can use --force here.")
11 .kind("info")
12 .style("+")
13 .width(40)
14 .print();
15}Sourcepub fn width(self, width: usize) -> Self
pub fn width(self, width: usize) -> Self
Sets the total width of the note box.
This method consumes self and returns a new Note instance,
allowing for method chaining. The content will be padded to fit
within this width.
§Arguments
width- The desired total width of the note box in characters.
§Returns
The Note instance with the updated width.
Examples found in repository?
3fn main() {
4 Note::new("Be careful with this setting.")
5 .kind("warning")
6 .style("rounded")
7 .width(40)
8 .print();
9
10 Note::new("Tip: You can use --force here.")
11 .kind("info")
12 .style("+")
13 .width(40)
14 .print();
15}Sourcepub fn print(&self)
pub fn print(&self)
Prints the formatted note to the console.
This method constructs the note with its borders, icon, styled text, and padding, then prints it to standard output.
Examples found in repository?
3fn main() {
4 Note::new("Be careful with this setting.")
5 .kind("warning")
6 .style("rounded")
7 .width(40)
8 .print();
9
10 Note::new("Tip: You can use --force here.")
11 .kind("info")
12 .style("+")
13 .width(40)
14 .print();
15}