Skip to content

Commit

Permalink
Introduce more themes to iced_highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 19, 2023
1 parent 93d6f74 commit ff78e97
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 5 additions & 1 deletion examples/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ impl Application for Editor {
}

fn theme(&self) -> Theme {
Theme::Dark
if self.theme.is_dark() {
Theme::Dark
} else {
Theme::Light
}
}
}

Expand Down
35 changes: 28 additions & 7 deletions highlighter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,50 @@ impl Highlight {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Theme {
SolarizedDark,
InspiredGitHub,
Base16Mocha,
Base16Ocean,
Base16Eighties,
InspiredGitHub,
}

impl Theme {
pub const ALL: &[Self] =
&[Self::SolarizedDark, Self::InspiredGitHub, Self::Base16Mocha];
pub const ALL: &[Self] = &[

Check warning on line 171 in highlighter/src/lib.rs

View workflow job for this annotation

GitHub Actions / all

`&` without an explicit lifetime name cannot be used here
Self::SolarizedDark,
Self::Base16Mocha,
Self::Base16Ocean,
Self::Base16Eighties,
Self::InspiredGitHub,
];

pub fn is_dark(self) -> bool {
match self {
Self::SolarizedDark
| Self::Base16Mocha
| Self::Base16Ocean
| Self::Base16Eighties => true,
Self::InspiredGitHub => false,
}
}

fn key(&self) -> &'static str {
match self {
Theme::InspiredGitHub => "InspiredGitHub",
Theme::Base16Mocha => "base16-mocha.dark",
Theme::SolarizedDark => "Solarized (dark)",
Theme::Base16Mocha => "base16-mocha.dark",
Theme::Base16Ocean => "base16-ocean.dark",
Theme::Base16Eighties => "base16-eighties.dark",
Theme::InspiredGitHub => "InspiredGitHub",
}
}
}

impl std::fmt::Display for Theme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Theme::InspiredGitHub => write!(f, "Inspired GitHub"),
Theme::Base16Mocha => write!(f, "Mocha"),
Theme::SolarizedDark => write!(f, "Solarized Dark"),
Theme::Base16Mocha => write!(f, "Mocha"),
Theme::Base16Ocean => write!(f, "Ocean"),
Theme::Base16Eighties => write!(f, "Eighties"),
Theme::InspiredGitHub => write!(f, "Inspired GitHub"),
}
}
}
Expand Down

0 comments on commit ff78e97

Please sign in to comment.