1use std::io::Read;
2
3fn colr(colors : &[Vec<u8>], id : usize) -> iced::Color{
4 iced::Color::from_rgb8(colors[id][0], colors[id][1], colors[id][2])
5}
6fn pywal_palette(colors : &[Vec<u8>]) -> iced::theme::Palette{
7 let mut pallete = iced::Theme::Dark.palette();
8 {
9 pallete.background = colr(colors, 0);
10 pallete.primary = colr(colors, 4);
11 pallete.success = colr(colors, 2);
12 pallete.danger = colr(colors, 1);
13 }
14 pallete
15}
16fn get_pywal_colors() -> Result<Vec<Vec<u8>>, Box<dyn std::error::Error>>{
17 let path = std::env::home_dir()
18 .unwrap_or_default()
19 .to_string_lossy()
20 .to_string()
21 + "/.cache/wal/colors-rgb";
22 let mut colors = std::fs::File::open(&path)?;
23 let mut colors_string = "".to_string();
24 colors.read_to_string(&mut colors_string)?;
25 Ok(colors_string
26 .lines()
27 .map(|line| {
28 line.split(",")
29 .map(|l| l.parse::<u8>().unwrap_or(0))
30 .collect::<Vec<_>>()
31 })
32 .collect::<Vec<_>>())
33}
34pub fn color_cheme() -> Result<iced::Theme, Box<dyn std::error::Error>> {
35 let colors = get_pywal_colors()?;
36 let palette = pywal_palette(&colors);
37 let theme = iced::Theme::custom("pywal".to_string(), palette);
38 Ok(theme)
39}
40