Skip to content

Commit

Permalink
Use COSMIC Default themes as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
snaggen authored and jackpot51 committed Apr 14, 2024
1 parent c63e19e commit 3e41d26
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::sync::OnceLock;
use crate::fl;

pub const CONFIG_VERSION: u64 = 1;
pub const COSMIC_THEME_DARK: &str = "COSMIC Dark";
pub const COSMIC_THEME_LIGHT: &str = "COSMIC Light";

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum AppTheme {
Expand Down Expand Up @@ -193,8 +195,8 @@ impl Default for Profile {
Self {
name: fl!("new-profile"),
command: String::new(),
syntax_theme_dark: "COSMIC Dark".to_string(),
syntax_theme_light: "COSMIC Light".to_string(),
syntax_theme_dark: COSMIC_THEME_DARK.to_string(),
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
tab_title: String::new(),
}
}
Expand Down Expand Up @@ -239,8 +241,8 @@ impl Default for Config {
opacity: 100,
profiles: BTreeMap::new(),
show_headerbar: true,
syntax_theme_dark: "COSMIC Dark".to_string(),
syntax_theme_light: "COSMIC Light".to_string(),
syntax_theme_dark: COSMIC_THEME_DARK.to_string(),
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
use_bright_bold: false,
default_profile: None,
}
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,14 @@ impl App {
let colors = self
.themes
.get(&self.config.syntax_theme(profile_id_opt))
.or_else(|| {
let mut keys: Vec<_> = self.themes.keys().collect();
keys.sort_by(|a, b| (&a.0).cmp(&b.0));
keys.first().and_then(|key| self.themes.get(key))
.or_else(|| match self.config.color_scheme_kind() {
ColorSchemeKind::Dark => self
.themes
.get(&(config::COSMIC_THEME_DARK.to_string(), ColorSchemeKind::Dark)),
ColorSchemeKind::Light => self.themes.get(&(
config::COSMIC_THEME_LIGHT.to_string(),
ColorSchemeKind::Light,
)),
});
match colors {
Some(colors) => {
Expand Down
8 changes: 5 additions & 3 deletions src/terminal_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use hex_color::HexColor;
use palette::{encoding::Srgb, rgb::Rgb as PRgb, FromColor, Okhsl};
use std::{collections::HashMap, fs};

use crate::config::{ColorScheme, ColorSchemeAnsi, ColorSchemeKind};
use crate::config::{
ColorScheme, ColorSchemeAnsi, ColorSchemeKind, COSMIC_THEME_DARK, COSMIC_THEME_LIGHT,
};

// Fill missing dim/bright colors with derived values from normal ones.
#[allow(dead_code)]
Expand Down Expand Up @@ -338,11 +340,11 @@ fn cosmic_light() -> Colors {
pub fn terminal_themes() -> HashMap<(String, ColorSchemeKind), Colors> {
let mut themes = HashMap::new();
themes.insert(
("COSMIC Dark".to_string(), ColorSchemeKind::Dark),
(COSMIC_THEME_DARK.to_string(), ColorSchemeKind::Dark),
cosmic_dark(),
);
themes.insert(
("COSMIC Light".to_string(), ColorSchemeKind::Light),
(COSMIC_THEME_LIGHT.to_string(), ColorSchemeKind::Light),
cosmic_light(),
);
themes
Expand Down

0 comments on commit 3e41d26

Please sign in to comment.