Repository: zellij-org/zellij
File: src/common/os_input_output.rs (Rust)

Code before:
                SIGTERM | SIGINT | SIGQUIT => {
                    break;
                }
                _ => unreachable!(),
            }
        }
    }
    fn load_palette(&self) -> Palette {
        let palette = match Colors::new("xresources") {
            Some(palette) => {
                let fg = if let Some(foreground) = hex_to_rgb(&palette.fg) {
                    foreground
                } else {
                    return default_palette();
                };

                let bg = if let Some(background) = hex_to_rgb(&palette.bg) {
                    background
                } else {
                    return default_palette();
                };

                let colors: Vec<(u8, u8, u8)> = palette
                    .colors
                    .iter()
                    .map(|c| hex_to_rgb(c).unwrap())
                    .collect();
                let theme = detect_theme(bg);
                Palette {
                    source: PaletteSource::Xresources,
                    theme,
                    fg,
                    bg,
                    black: colors[0],
                    red: colors[1],
                    green: colors[2],
                    yellow: colors[3],
                    blue: colors[4],
                    magenta: colors[5],
                    cyan: colors[6],
                    white: colors[7],
                    orange: colors[9],
                }
            }
            None => default_palette(),
        };
        palette
    }
}

impl Clone for Box<dyn OsApi> {

Review comment (suggestion):
:thinking: In my environment, all elements of `palette.colors` are `None`, so it might be better to consider the case `c` is `None`.

Code after:
                SIGTERM | SIGINT | SIGQUIT => {
                    break;
                }
                _ => unreachable!(),
            }
        }
    }
    fn load_palette(&self) -> Palette {
        let palette = match Colors::new("xresources") {
            Some(palette) => {
                let fg = if let Some(foreground) = palette.fg.as_deref().map(hex_to_rgb) {
                    foreground
                } else {
                    return default_palette();
                };

                let bg = if let Some(background) = palette.bg.as_deref().map(hex_to_rgb) {
                    background
                } else {
                    return default_palette();
                };

                // NOTE: `16` is the same as the length of `palette.colors`.
                let mut colors: [(u8, u8, u8); 16] = [(0, 0, 0); 16];
                for (idx, color) in palette.colors.iter().enumerate() {
                    if let Some(c) = color {
                        colors[idx] = hex_to_rgb(c);
                    } else {
                        return default_palette();
                    }
                }
                let theme = detect_theme(bg);
                Palette {
                    source: PaletteSource::Xresources,
                    theme,
                    fg,
                    bg,
                    black: colors[0],
                    red: colors[1],
                    green: colors[2],
                    yellow: colors[3],
                    blue: colors[4],
                    magenta: colors[5],
                    cyan: colors[6],
                    white: colors[7],
                    orange: colors[9],
                }
            }
            None => default_palette(),
        };
        palette