jomy10/simple_colors

This crate provides simple macros for formatting strings with colors, backgrounds and styles like bold,...

This crate provides simple macros for formatting strings with colors, backgrounds and styles like bold, italic and underlined

Simple Colors

. The crate does not use any external dependencies.

Installing

Add the following line to your Cargo.toml file:

[dependencies]
simple_colors = "1"

Overview

Colors

You can style text with colors:

use simple_colors::{white, red, printlnc};
println!("{}", red!("This is red"));
printlnc!(red!("This is also red"));
printlnc!(format!("{}, {}.", white!("This is white"), red!("this is red")))

Output:

The available colors:

  • black
  • white
  • yellow & light_yellow
  • red & light_red
  • cyan & light_cyan
  • blue & light_blue
  • magenta & light_magenta
  • green & light_green
  • dark_grey & grey

Preview

Backgrounds

You can also add backgrounds:

use simple_colors::{white, bg_black, printlnc};

printlnc!(bg_black!(white!("Black background with white text")));

Styles

You can also make your text bold, italic or underlined.

use simple_colors::bold;

printlnc!(bold!("This text is bold"));

Combining styles

You can combine all of the different macros to style your text.

Custom styles

You can also specify custom styles:

use simple_colors::{color, Color, Style};

enum MyCustomStyles {
    Style1,
    Style2
}
impl simple_colors::custom::Style for MyCustomStyles {
    fn get_style_code(&self) -> String {
        match self {
            // Style1 will be bold and light blue
            MyCustomStyles::Style1 => "\x1b[1m\x1b[94m".to_string(),
            // Style2 will be bold and red
            MyCustomStyles::Style2 =>
                format!(
                    "{}{}",
                    Style::Bold.get_style_code(),
                    Color::Red.get_style_code()
                )
        }
    }
}
 println!("{}", color!(MyCustomStyles::Style2, "Some text that is both bold and red"))

Printlnc! and printc!

printlnc!() and printc!() are two methods for printing your formatted text like so:

printlnc!(blue!("Hello world"));

which is a replacement for:

println!("{}", blue!("Hello world"));

Contributing

Everything should be covered in this crate. If you find a bug, feel free to open an issue and then making a pull request (if you know how to fix the bug). If you can think of improvements, they are also always welcome.

License

This crate is licensed under the MIT License or the Apache-2.0 license.

Versions

Find the latest versions by id

v1.0.1 - Jan 19, 2022

  • Added assets to exclude so they are not included in the crate.

This is probably the final version of the crate as there are no more planned features. I will continue to maintain the crate.

Information - Updated Sep 15, 2022

Stars: 0
Forks: 0
Issues: 0

Rust library for Self Organising Maps (SOM)

Add rusticsom as a dependency in Cargo

Rust library for Self Organising Maps (SOM)

Rust library for parsing configuration files

The 'option' can be any string with no whitespace

Rust library for parsing configuration files

Rust library for the Pimoroni Four Letter pHAT

This library aims to port ht16k33 (or rather a fork, as of right now) so credit goes to ht16k33-diet

Rust library for the Pimoroni Four Letter pHAT

Rust library for emulating 32-bit RISC-V

This library can execute instructions against any memory and register file that implements

Rust library for emulating 32-bit RISC-V

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

You can use actix-web as a backend instead of hyper

Rust library for connecting to the IPFS HTTP API using Hyper/Actix

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

This module provides two high level functions, getfacl and setfacl

Rust library to manipulate file system access control lists (ACL) on macOS, Linux, and FreeBSD

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

This is the place to translate Having a documentation in your native language is essential if you don't speak English, and still enjoyable even if...

Rust library translation (rust-src/rust-std/stdlib/rustlib translation)

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

enabling remote control support for embedded project

Rust library for using Infrared hardware decoders (For example a Vishay TSOP* decoder),

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

open up an issue on this repository and let us know

Rust library for interaction with the OriginTrail Decentralized Knowledge Graph

Rust library for parsing COLLADA files

Notice: This library is built around files exported from Blender 2

Rust library for parsing COLLADA files

web-library-rust

A basic CRUD application that represents books in a library

web-library-rust
Facebook Instagram Twitter GitHub Dribbble
Privacy