Crate pealn

Crate pealn 

Source
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

NamePreviewExample 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

StyleExample CodeDescription
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)Strikethrough

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