Expand description
§Introduction
Pealn is a Rust library to print colored and styled to console
§Features
- Fatest Pealn is fastest among other famous ones. see benchmarks
- Compile time format pealn codes during compile time
- Easy to use Apply modification inside string
- Pre defined Colors Common colors are already defined
- Text Styles Add Styles like , bold , italic , underline and more
- Use RGB colors Apply colors using RGB value
§Installation
Add Pealn to your Cargo.toml , see crates.io/Pealn for latest version
[dependencies]
pealn = "0.3"Add Pealn using Cargo CLI:
cargo add Pealn§How to use it
§Format
[foreground,background,styles....](text) Note: the order of foreground , background and styles could be anything
§Understand By exmaples
Lets add forground color to a text using
pealn!("[green](John Doe)") output
John Doe
Lets print more text with diffrent foreground colors
pealn!("Name : [green](John Doe) \n Age : [yellow](32)") output
Name : John Doe
Age : 32
Now lets add both foreground and background color
pealn!("Name : [green,yellow](John Doe) \n Age : [yellow](32)") output
Name: John Doe
Age : 32
§*Note first color will be considered as foreground and next color will be consider as background , you cannot add more than 2 color
Now lets change only bacground of John Doe of Name not foreground
To do it you have to define first color or foreground color as Default
pealn!("Name : [default,yellow](John Doe) \n Age : [yellow](32)") output
Name: John Doe
Age : 32
§🎨 Available Predefined Colors
| Name | Preview | Example Code |
|---|---|---|
| Red | â– | [red](text) |
| Green | â– | [green](text) |
| Blue | â– | [blue](text) |
| Yellow | â– | [yellow](text) |
| Cyan | â– | [cyan](text) |
| Purple | â– | [purple](text) |
| Magenta | â– | [magenta](text) |
| Black | â– | [black](text) |
| White | â– | [white](text) |
Note: Color preview may not render
§So didnt found your choice on predefined table above No problem you can use RGB colors
[(r,g,b),background,styles....](text) Lets use RGB to give any color to your text
To use RGB use (r,g,b) instead of predefined color
pealn!("[(190, 3, 252)](John Doe)") output
John Doe
§Adding Styles to your Text
You can add multiple styles but styles should not be repeated
lets print name in bold
pealn!("[bold](John Doe)") output
John Doe
lets print name in bold and italic
pealn!("[bold,italic](John Doe)") output
John Doe
lets print name in bold and italic with yellow foreground
pealn!("[yellow,bold,italic](John Doe)") output
John Doe
lets print name in bold and italic with yellow foreground and blue background
pealn!("[yellow,blue,bold,italic](John Doe)") output
John Doe
§✨ Available Styles
| Style | Example Code | Description |
|---|---|---|
| Bold | [bold](text) | Bold text |
| Dim | [dim](text) | Dim/faint text |
| Italic | [italic](text) | Italic text |
| Underline | [underline](text) | Underlined text |
| Blink | [blink](text) | Blinking text (not always supported) |
| Reverse | [reverse](text) | Reverse video |
| Hidden | [hidden](text) | Hidden text |
| Strikethrough | [strikethrough](text) |
Some styles may not be supported in all terminals.
§Pealn is an Alternative
Pealn has alternative of below macros , their argument types , working all are same as traditional , but with a pealn color and style formatting
| Traditional Rust Macro | Pealn Macro Alternative |
|---|---|
print!() | pea!() |
println!() | pealn!() |
write!() | pealn_write!() |
writeln!() | pealn_writeln!() |
format!() | pealn_format!() |
eprint!() | pealn_eprint!() |
eprintln!() | pealn_eprintln!() |
Macros§
- pea
- pea! is an alternative to print! macro. print on same line with colored and styles
- pealn
- pealn! is an alternative to println! macro. print new line with colored and styles
- pealn_
eprint - pealn_eprint! is an alternative to eprint! macro. print error on same line with colored and styles
- pealn_
eprintln - pealn_eprintln! is an alternative to eprintln! macro. print error on next line with colored and styles
- pealn_
format - pealn_format! is an alternative to format! macro. Creates a String using interpolation of runtime expressions. The first argument format! receives is a format string. This must be a string literal. The power of the formatting string is in the {}s contained. Additional parameters passed to format! replace the {}s within the formatting string in the order given unless named or positional parameters are used.
- pealn_
write - pealn_write is an alternative to write! macro. Writes formatted data into a buffer.
- pealn_
writeln - pealn_writeln is an alternative to writeln! macro. Writes formatted data into a buffer.