Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThemeDefaults proof of concept #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CosmicHorrorDev
Copy link
Contributor

Resolves #478

Just a simple proof of concept for how the ideas in #478 could look. This adds in a ThemeDefaults enum and a Theme::load_default() constructor that can handle loading a single default theme

Random thoughts:

  • bincode doesn't support easily ignoring values, so all themes leading up to the one you want are still loaded
  • ThemeDefaults should be #[non_exhaustive] if you want to support adding more default themes without a semver breaking change
  • ThemeDefaults should probably derive more traits, but I left it barebones for the proof-of-concept
  • ThemeDefaults::as_theme_name() wasn't exposed publicly because of the potential confusion that the theme name should match the theme.name.unwrap() which is not the case for some of the defaults (this confused me at least)
  • Luckily this wasn't a schema change for default.themedump since bincode serializes a struct with a single field mapped to a value as just the single value

Overall this means that you can write code like this to load a single default theme which is nice when you're only dealing with single themes

use syntect::highlighting::{Theme, ThemeDefaults};

let inspired_gh = Theme::load_default(ThemeDefaults::InspiredGitHub);

@CosmicHorrorDev CosmicHorrorDev marked this pull request as ready for review May 29, 2023 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for loading a single default theme
1 participant