4 releases (2 breaking)

0.3.0 Apr 3, 2023
0.2.0 Jun 18, 2022
0.1.3 Dec 13, 2021
0.1.2 Nov 6, 2021

#1334 in Parser implementations

Download history 209/week @ 2024-07-21 246/week @ 2024-07-28 187/week @ 2024-08-04 259/week @ 2024-08-11 186/week @ 2024-08-18 231/week @ 2024-08-25 217/week @ 2024-09-01 838/week @ 2024-09-08 326/week @ 2024-09-15 242/week @ 2024-09-22 218/week @ 2024-09-29 209/week @ 2024-10-06 223/week @ 2024-10-13 176/week @ 2024-10-20 156/week @ 2024-10-27 66/week @ 2024-11-03

640 downloads per month
Used in nyaa

MIT license

16KB
311 lines

Color -> TUI

build build

Parse HEX colors to ratatui's Rgb colors.

Example

  • #C3F111 -> Color::Rgb(195,241,17)
  • #CFB -> Color::Rgb(204,255,187)
  • 142 -> Color::Indexed(142)

Usage

#[derive(Serialize, Deserialize, PartialEq)]
sruct ColorStruct {
    #[serde(with = "color_to_tui"]
    color: ratatui::style::Color,
    #[serde(with = "color_to_tui::optional"]
    optional_color: Option<ratatui::style::Color>,
}

let color_text =  r###"{ "color" : "#12FC1C", "optional_color" : "123" }"###
let t: ColorStruct = serde_json::from_str::<ColorStruct>(color_text).unwrap();

let c = ColorStruct {
    color: Color::Rgb(18, 252, 28),
    optional_color: Option<Color::Indexed(123)>,
};

assert_eq!(t, c);

Dependencies

~6.5MB
~111K SLoC