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

Configurable sources (and source hierarchy) #62

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

Softsun2
Copy link
Contributor

It appears a few people want support for configurable sources. As I mentioned in my previously closed pr I was thinking of doing so, I believe this is a more proper solution than my last pr but this is still my first time writing rust so I would review my additions if you're interested in this feature.

Configuration Hierarchy

The config.toml source lists take precedence over ~/.local/share/flavours/base16/sources.yaml and ~/.local/share/flavours/base16/sources.yaml takes precedence over the default source lists.

Configuration Schema

The config.toml now supports configuring source lists and extra sources.

/// Structure for configuration
#[derive(Deserialize, Debug)]
pub struct Config {
    pub shell: Option<String>,
    pub schemes: Option<String>,
    pub templates: Option<String>,
    pub extra_scheme: Option<Vec<ExtraSource>>,
    pub extra_template: Option<Vec<ExtraSource>>,
    pub item: Option<Vec<ConfigItem>>,
    pub items: Option<Vec<ConfigItem>>,
}
  • schemes: is a string of the link to a repo of a list of schemes of this format
  • templates: is a string of the link to a repo of a list of templates of this format
  • extra_scheme: is a vector of extra schemes. Each extra scheme is added to the appropriate list.yaml, maintaining sorted order.
  • extra_template: is a vector of extra templates. Each extra scheme is added to the appropriate list.yaml, maintaining sorted order.

Extra Schemes and Templates

In the case where a user would like to configure schemes and templates that are not included in their active source lists they may provide extra schemes and templates that will be inserted into the appropriate list.yaml file. The Config struct fields extra_scheme and extra_template are vectors of the following extra source structure.

/// Structure for configuration extra sources
#[derive(Deserialize, Debug)]
pub struct ExtraSource{
    pub name: String,
    pub source: String,
}
  • name: is a string of the name of the scheme or template, the key to the sources in the list.yaml files.
  • source: is a string of a link to a base16 scheme or template repo of the respective linked format. The source appears as the value to the source name in the list.yaml files.

Example

I've attached a simple config.toml that shows the new features with some snippets of the resulting files after running flavours update all.

# config.toml
schemes = "https://github.com/Softsun2/base16-schemes-source"
# templates = "my-templates"

[[extra_scheme]]
name = "tarko"
source = "https://github.com/Softsun2/base16-tarko-scheme"

Here I'm choosing to use a non-default scheme list, the default template list, and an extra scheme that's not included in the scheme list I've configured.

# ~/.local/share/flavours/base16/sources.yaml
schemes: https://github.com/Softsun2/base16-schemes-source
templates: https://github.com/chriskempson/base16-templates-source.git

You can see that the configured source list was written as expected.

# ~/.local/share/flavours/base16/sources/schemes/list.yaml
...
synth-midnight: https://github.com/michael-ball/base16-synth-midnight-scheme
tango: https://github.com/Schnouki/base16-tango-scheme
tarko: https://github.com/Softsun2/base16-tarko-scheme
tender: https://github.com/DanManN/base16-tender-scheme
twilight: https://github.com/hartbit/base16-twilight-scheme
...

This is a snippet of the schemes list yaml file. Just shows that the extra scheme (tarko) made it's way into the list of schemes.

Notes

I haven't really tested this much, I plan on using this fork of flavours, I'll report/fix bugs I run into. I have zero rust experience, so I would review my changes closely if this is a feature you would like to implement.

@Misterio77
Copy link
Owner

I like it a lot! I was actually thinking of a way to allow users to include non-listed schemes or templates (without forking the sources), and I think you pretty much nailed it with a great design.

Code seems fine. I'm terribly sorry about the spaghetti code, it was my first real rust program. I should refactor it sometime (tm).

I will merge it as soon as I test it. Thanks a lot!

@Misterio77
Copy link
Owner

Seems to work nicely!

Something I think might be useful is setting the URLs to an empty string could perhaps skip cloning and write an empty list (for people who prefer to not use any list). I will see if I can implement this in a follow up commit.

Thanks again!

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.

None yet

2 participants