Skip to content
New issue

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

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

Already on GitHub? # to your account

Subcommand to list out available themes #48

Merged
merged 1 commit into from
Dec 19, 2020

Conversation

gillespiecd
Copy link
Contributor

@gillespiecd gillespiecd commented Nov 10, 2020

Possibly resolves #46 (not entirely sure what the ask is), or at the very least hopefully adds some useful functionality.

The goal is to display to users which themes are available to use, so that they have an idea of what can be run into preview or generate.

Output

> ./target/debug/vivid themes
ayu
jellybeans
molokai
snazzy
solarized-light
solarized-dark

@sharkdp
Copy link
Owner

sharkdp commented Nov 29, 2020

@gillespiecd Any particular reason why you closed this PR?

@gillespiecd
Copy link
Contributor Author

gillespiecd commented Nov 29, 2020

@sharkdp After some thought, I wasn't sure if it was going to be useful or not. If you feel like it will be a good addition, then I can re-open.

@sharkdp
Copy link
Owner

sharkdp commented Nov 29, 2020

Didn't have the time to take a closer look at the code, but I'd certainly like to, at some point. Let's leave it open for now.

Thank you for your contribution!

@sharkdp sharkdp reopened this Nov 29, 2020
@gillespiecd
Copy link
Contributor Author

@sharkdp Sounds good, thanks!

@gillespiecd gillespiecd force-pushed the listthemes branch 7 times, most recently from 7276518 to 23f0ff4 Compare December 1, 2020 23:32
src/main.rs Outdated
@@ -140,7 +169,8 @@ fn run() -> Result<()> {
SubCommand::with_name("preview")
.about("Preview a given theme")
.arg(Arg::with_name("theme").help("Name of the color theme")),
);
)
.subcommand(SubCommand::with_name("themes").about("Available themes for use"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe: "Print a list of available themes"?

@@ -61,6 +63,33 @@ fn load_filetypes_database(matches: &ArgMatches, user_config_path: &PathBuf) ->
}
}

fn available_theme_names(user_config_path: &PathBuf) -> Result<Vec<String>> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we list the user-themes in addition to the builtin themes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, this should hopefully work now. It captures all possible theme paths.

I ran a copy to test out.

> cp themes/ayu.yml $HOME/.config/vivid/themes/ayu2.yml
> ./target/debug/vivid themes
ayu
ayu2
jellybeans
molokai
snazzy
solarized-dark
solarized-light

src/main.rs Outdated
.map_err(VividError::IoError)?
.file_name()
.into_string()
.map_err(|n| VividError::InvalidFileName(n.into_string().unwrap()))?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If into_string has failed in the line above this one, it will also fail here inside map_err. Which, in turn, will cause .unwrap() to panic.

You can try this by running

touch ~/.config/vivid/themes/$(printf 'whatever\xFE')

before trying to list the themes.

What you could do instead (either in the error handling, or directly for listing the themes) would be to use .as_os_str().to_string_lossy() which replaces invalid UTF-8 characters with a symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, thanks for the detailed explanation, it did seem like bad practice to unwrap there, makes sense now.

@gillespiecd gillespiecd force-pushed the listthemes branch 2 times, most recently from cdfd6dd to cf9dc0c Compare December 2, 2020 16:55
Improve error handling for theme listing
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sharkdp sharkdp merged commit aece8d8 into sharkdp:master Dec 19, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to list themes
2 participants