https://github.com/robertwayne/iridescent
Terminal text styling via ANSI escape sequences.
https://github.com/robertwayne/iridescent
ansi colors command-line-interface styling terminal
Last synced: 2 months ago
JSON representation
Terminal text styling via ANSI escape sequences.
- Host: GitHub
- URL: https://github.com/robertwayne/iridescent
- Owner: robertwayne
- License: apache-2.0
- Created: 2022-02-07T07:08:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T01:37:50.000Z (about 2 years ago)
- Last Synced: 2025-12-13T23:55:26.438Z (6 months ago)
- Topics: ansi, colors, command-line-interface, styling, terminal
- Language: Rust
- Homepage:
- Size: 101 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Iridescent
---
## Features
`iridescent` is a dependency-free library for styling terminal text easily.
It supports basic ANSI sequences, Xterm-256 colors, and RGB. You can operate
directly on `&str` and `String` types without needing to worry about
conversions.
It is important to note that not all terminals support all features. While
*most* modern terminals will support up to true RGB colors, certain text modes,
such as `blink`, are not reliable.
## Usage
```toml
[dependencies]
iridescent = { version = "0.2" }
```
The only requirement is that you import the `Styled` trait into the module you
plan on using library methods. Once you have declared it at the top of your
module, the methods will be available on all `&str` and `String` types.
Note that all `Styled` methods can be chained, as seen in the example above
where first we call the foreground method, followed by the bold method. These do
not have to be in any specific order.
### Using Basic Colors
```rust
use iridescent::{constants::GREEN, Styled};
fn main() {
// Here we can use a built-in method called `.green()` to apply the color.
// Every basic color has a helper method for the foreground, as this is
// the most common thing to style.
let s = "Hello".green().bold();
// But we could manually do it this way, too. You'll need to import the
// color codes from the constants file, of course.
let s2 = "world".foreground(GREEN).bold();
println!("{}, {}!", s, s2);
}
```
### Using 256-bit & RGB Colors
```rust
use iridescent::{Styled, Rgb};
fn main() {
// We use .foreground() for a 256-bit color; in this case, 155 - or a lime green.
let s = "Hello".foreground(155).underline();
// Here we combine a 256-bit color with an RGB color. First, we set the foreground
// to an RGB value of (4, 11, 214) - some variant of dark blue. Next, we set
// the background to a value of 195 - a very light, almost white, blue. In
// addition, we apply some modes (underline and blink) to our text.
//
// As you can see, mixing and matching various sequence types is no problem!
let s2 = "world"
.foreground(&[4, 11, 214])
.background(195)
.blink();
println!("{}, {}!", s, s2);
}
```
### Hexadecimal Colors
As of `v0.2`, you can now use hexadecimal color literals, as well!
```rust
use iridescent::{Styled, constants::{RED, WHITE}};
fn main() {
let hello = "Hello".foreground("#ff00ff").bold();
let world = "world".foreground("#00ff00").background("#0000ff");
println!("{hello}, {world}!");
}
```
See
**[here](https://docs.rs/iridescent/latest/iridescent/styled/trait.Styled.html)**
for all the methods available.
## Examples
If you have cloned the `iridescent` repository, you can run an example with the
command `cargo run --example `. You can add features, if needed,
with --features .
| Example | File | Description | Features |
|---------|-----------------------------------------|--------------------------------------------------------------------------|------------|
| rainbow | [colors.rs](/examples/colors.rs) | Shows off all base colors in the terminal. | |
| rgb | [rainbow.rs](/examples/rainbow.rs) | Shows off both 8-bit and 24-bit depth randomized colors in the terminal. | `random` |
| modes | [modes.rs](/examples/modes.rs) | Shows off the various text modes in the terminal. | |
## Feature Flags
| Flag | Default | Description | Dependencies |
|----------|----------|-------------------------------------------------------------------------------------|--------------|
| `random` | Disabled |Enables the use of `Color::random()` and `Color::random_rgb()` | `rand` |
## License
Iridescent is dual-licensed under either
- **[MIT License](/LICENSE-MIT)**
- **[Apache License, Version 2.0](/LICENSE-APACHE)**
at your option.