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

#1491 in Parser implementations

Download history 187/week @ 2024-10-08 220/week @ 2024-10-15 165/week @ 2024-10-22 141/week @ 2024-10-29 43/week @ 2024-11-05 28/week @ 2024-11-12 36/week @ 2024-11-19 31/week @ 2024-11-26 25/week @ 2024-12-03 55/week @ 2024-12-10 23/week @ 2024-12-17 5/week @ 2024-12-24 12/week @ 2024-12-31 30/week @ 2025-01-07 26/week @ 2025-01-14 15/week @ 2025-01-21

83 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

~5.5MB
~90K SLoC