https://github.com/uttarayan21/color-to-tui
Parse hex colors to tui::style::Color
https://github.com/uttarayan21/color-to-tui
Last synced: about 1 month ago
JSON representation
Parse hex colors to tui::style::Color
- Host: GitHub
- URL: https://github.com/uttarayan21/color-to-tui
- Owner: uttarayan21
- Created: 2021-11-04T12:11:49.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T06:16:35.000Z (over 1 year ago)
- Last Synced: 2025-04-06T15:05:06.093Z (about 1 month ago)
- Language: Rust
- Size: 37.1 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Color -> TUI
[][color-to-tui]
[][mirror]Parse HEX colors to [ratatui](https://github.com/tui-rs-revival/ratatui)'s [Rgb](https://docs.rs/ratatui/latest/ratatui/style/enum.Color.html) colors.
## Example
- `#C3F111` -> `Color::Rgb(195,241,17)`
- `#CFB` -> `Color::Rgb(204,255,187)`
- `142` -> `Color::Indexed(142)`## Usage
```rust
#[derive(Serialize, Deserialize, PartialEq)]
sruct ColorStruct {
#[serde(with = "color_to_tui")]
color: ratatui::style::Color,
#[serde(with = "color_to_tui::optional")]
optional_color: Option,
}let color_text = r###"{ "color" : "#12FC1C", "optional_color" : "123" }"###
let t: ColorStruct = serde_json::from_str::(color_text).unwrap();let c = ColorStruct {
color: Color::Rgb(18, 252, 28),
optional_color: Option,
};assert_eq!(t, c);
```[color-to-tui]: https://git.uttarayan.me/uttarayan/color-to-tui
[mirror]: https://github.com/uttarayan21/color-to-tui