color-to-tui

Crates.iocolor-to-tui
lib.rscolor-to-tui
version0.3.0
sourcesrc
created_at2021-11-06 21:08:14.449135
updated_at2023-04-03 10:11:42.182758
descriptionParse colors and convert them to ratatui::style::Colors
homepagehttps://git.uttarayan.me/uttarayan/color-to-tui
repositoryhttps://git.uttarayan.me/uttarayan/color-to-tui
max_upload_size
id477842
size15,729
Uttarayan Mondal (uttarayan21)

documentation

README

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);
Commit count: 0

cargo fmt