-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use `rgb` crate * Explain usage in Windows console * Axe `main.rs` * Fix "temporary value dropped while borrowed" * Fix formatting of pointers * Package the crate better
- Loading branch information
1 parent
90a405e
commit 6565959
Showing
11 changed files
with
312 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust.all_targets": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
[package] | ||
name = "ansi_rgb" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = ["Matt Thomas <me@matthewathomas.com>"] | ||
edition = "2018" | ||
description = "Simple `no_std` compatible ANSI escape character coloring" | ||
license-file = "LICENSE" | ||
description = "Colorful console text using ANSI escape sequences" | ||
license = "MIT" | ||
categories = ["no-std", "command-line-interface"] | ||
keywords = ["ansi", "color", "rgb", "no_std", "console"] | ||
readme = "README.md" | ||
repository = "https://github.com/rust-osdev/ansi_rgb" | ||
homepage = "https://github.com/rust-osdev/ansi_rgb" | ||
documentation = "https://docs.rs/ansi_rgb" | ||
|
||
[badges] | ||
maintenance = { status = "actively-developed" } | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rgb = "0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,81 @@ | ||
# ansi_rgb | ||
ANSI escape code colors for `no_std` environments. | ||
Colorful console text using [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters). | ||
|
||
* Very simple API | ||
* Full color (using the [`rgb` crate](https://crates.io/crates/rgb)) | ||
* Colors all the [formatting traits](https://doc.rust-lang.org/std/fmt/#formatting-traits) | ||
* `no_std` compliant | ||
|
||
[![crates.io badge](https://img.shields.io/crates/v/ansi_rgb.svg)](https://crates.io/crates/ansi_rgb)<br/> | ||
[![docs.rs badge](https://docs.rs/ansi_rgb/badge.svg)](https://docs.rs/ansi_rgb)<br/> | ||
[![Downloads badge](https://img.shields.io/crates/d/ansi_rgb.svg)](https://crates.io/crates/ansi_rgb) | ||
|
||
Cargo.toml: | ||
```toml | ||
ansi_rgb = "0.2.0" | ||
``` | ||
|
||
# Foreground colors | ||
|
||
```rust | ||
use ansi_rgb::{ Foreground, red }; | ||
|
||
println!("{}", "Hello, world!".fg(red())); | ||
``` | ||
|
||
Output: | ||
|
||
<code style="color: red">Hello, world!</code> | ||
|
||
# Background colors | ||
|
||
```rust | ||
use ansi_rgb::{ Background, red }; | ||
|
||
println!("{}", "Hello, world!".bg(red())); | ||
``` | ||
|
||
Output: | ||
|
||
<code style="background: red">Hello, world!</code> | ||
|
||
# Mix and match | ||
|
||
```toml | ||
# Cargo.toml | ||
[dependencies] | ||
rbg = "0.8" | ||
``` | ||
|
||
```rust | ||
use ansi_rgb::{ Foreground, Background }; | ||
use rgb::RGB8; | ||
|
||
let fg = RGB8::new(123, 231, 111); | ||
let bg = RGB8::new(10, 100, 20); | ||
println!("{}", "Yuck".fg(fg).bg(bg)); | ||
``` | ||
|
||
Output: | ||
|
||
<code style="color: #7BE76F; background: #0A6414">Yuck</code> | ||
|
||
# Anything formattable | ||
|
||
```rust | ||
use ansi_rgb::*; | ||
|
||
fn main() { | ||
println!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}", | ||
"Red".fg(red()), | ||
"Orange".fg(orange()), | ||
"Yellow".fg(yellow()), | ||
"Yellow green".fg(yellow_green()), | ||
"Green".fg(green()), | ||
"Green cyan".fg(green_cyan()), | ||
"Cyan".fg(cyan()), | ||
"Cyan blue".fg(white()).bg(cyan_blue()), | ||
"Blue".fg(white()).bg(blue()), | ||
"Blue magenta".fg(white()).bg(blue_magenta()), | ||
"Magenta".fg(magenta()), | ||
"Magenta pink".fg(magenta_pink()), | ||
"Custom color".fg(Rgb::new(123, 231, 111)).bg(Rgb::new(10, 100, 20)) | ||
); | ||
} | ||
#[derive(Debug)] | ||
struct Foo(i32, i32); | ||
|
||
let foo = Foo(1, 2); | ||
println!("{:?}", foo.fg(green())); | ||
``` | ||
|
||
![Colorful output](https://imgur.com/9j1FLiU.png) | ||
Output: | ||
|
||
<code style="color: #00FF00">Foo(1, 2)</code> | ||
|
||
# Windows users | ||
|
||
You need to [set your console mode](https://docs.microsoft.com/en-us/windows/console/console-modes). Otherwise you'll get garbage like this: | ||
|
||
Context here: https://github.com/phil-opp/blog_os/issues/603 | ||
`�[48;2;159;114;0m �[0m` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use rgb::RGB8; | ||
|
||
/// Makes <code style="color: black; background: #FFFFFF">white</code> | ||
pub const fn white() -> RGB8 { | ||
RGB8::new(255, 255, 255) | ||
} | ||
|
||
/// Makes <code style="color: white; background: #000000">black</code> | ||
pub const fn black() -> RGB8 { | ||
RGB8::new(0, 0, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #FF0000">red</code> | ||
pub const fn red() -> RGB8 { | ||
RGB8::new(255, 0, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #FF8000">orange</code> | ||
pub const fn orange() -> RGB8 { | ||
RGB8::new(255, 128, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #FFFF00">yellow</code> | ||
pub const fn yellow() -> RGB8 { | ||
RGB8::new(255, 255, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #80FF00">yellow green</code> | ||
pub const fn yellow_green() -> RGB8 { | ||
RGB8::new(128, 255, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #00FF00">green</code> | ||
pub const fn green() -> RGB8 { | ||
RGB8::new(0, 255, 0) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #00FF80">green cyan</code> | ||
pub const fn green_cyan() -> RGB8 { | ||
RGB8::new(0, 255, 128) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #00FFFF">cyan</code> | ||
pub const fn cyan() -> RGB8 { | ||
RGB8::new(0, 255, 255) | ||
} | ||
|
||
/// Makes <code style="color: white; background: #0080FF">cyan blue</code> | ||
pub const fn cyan_blue() -> RGB8 { | ||
RGB8::new(0, 128, 255) | ||
} | ||
|
||
/// Makes <code style="color: white; background: #0000FF">blue</code> | ||
pub const fn blue() -> RGB8 { | ||
RGB8::new(0, 0, 255) | ||
} | ||
|
||
/// Makes <code style="color: white; background: #8000FF">blue magenta</code> | ||
pub const fn blue_magenta() -> RGB8 { | ||
RGB8::new(128, 0, 255) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #FF00FF">magenta</code> | ||
pub const fn magenta() -> RGB8 { | ||
RGB8::new(255, 0, 255) | ||
} | ||
|
||
/// Makes <code style="color: black; background: #FF0080">magenta pink</code> | ||
pub const fn magenta_pink() -> RGB8 { | ||
RGB8::new(255, 0, 128) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,83 @@ | ||
#![no_std] | ||
/*! | ||
Colorful console text using [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters). | ||
* Very simple API | ||
* Full color (using the [`rgb` crate](https://crates.io/crates/rgb)) | ||
* Colors all the [formatting traits](https://doc.rust-lang.org/std/fmt/#formatting-traits) | ||
* `no_std` compliant | ||
# Foreground colors | ||
```rust | ||
use ansi_rgb::{ Foreground, red }; | ||
println!("{}", "Hello, world!".fg(red())); | ||
``` | ||
Output: | ||
<code style="color: red">Hello, world!</code> | ||
# Background colors | ||
```rust | ||
use ansi_rgb::{ Background, red }; | ||
println!("{}", "Hello, world!".bg(red())); | ||
``` | ||
Output: | ||
<code style="background: red">Hello, world!</code> | ||
# Mix and match | ||
```toml | ||
# Cargo.toml | ||
[dependencies] | ||
rbg = "0.8" | ||
``` | ||
```rust | ||
use ansi_rgb::{ Foreground, Background }; | ||
use rgb::RGB8; | ||
let fg = RGB8::new(123, 231, 111); | ||
let bg = RGB8::new(10, 100, 20); | ||
println!("{}", "Yuck".fg(fg).bg(bg)); | ||
``` | ||
Output: | ||
<code style="color: #7BE76F; background: #0A6414">Yuck</code> | ||
# Anything formattable | ||
```rust | ||
# use ansi_rgb::*; | ||
#[derive(Debug)] | ||
struct Foo(i32, i32); | ||
let foo = Foo(1, 2); | ||
println!("{:?}", foo.fg(green())); | ||
``` | ||
Output: | ||
<code style="color: #00FF00">Foo(1, 2)</code> | ||
# Windows users | ||
You need to [set your console mode](https://docs.microsoft.com/en-us/windows/console/console-modes). Otherwise you'll get garbage like this: | ||
`�[48;2;159;114;0m �[0m` | ||
*/ | ||
|
||
mod background; | ||
mod colors; | ||
mod foreground; | ||
mod rgb; | ||
|
||
pub use background::*; | ||
pub use foreground::*; | ||
pub use rgb::*; | ||
pub use colors::*; | ||
pub use foreground::*; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.