-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Expose syntect theme and syntax sets #2030
Expose syntect theme and syntax sets #2030
Conversation
cd96e16
to
0b22913
Compare
src/assets.rs
Outdated
@@ -15,7 +15,7 @@ use crate::syntax_mapping::ignored_suffixes::IgnoredSuffixes; | |||
use crate::syntax_mapping::MappingTarget; | |||
use crate::{bat_warning, SyntaxMapping}; | |||
|
|||
use lazy_theme_set::LazyThemeSet; | |||
pub use lazy_theme_set::LazyThemeSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spontaneously I would like to have a public API that hides wether or not themes are lazy-loaded. So exporting the name LazyThemeSet
should be avoided if possible.
I'm a bit short on time, so maybe you could experiment a bit and see if that can be achieved?
src/assets/theme_set.rs
Outdated
} | ||
|
||
/// An iterator over all theme names | ||
pub fn themes(&self) -> impl Iterator<Item = &str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think perhaps this method would be better named theme_names
EDIT I made this change and force-pushed
2de7e6e
to
9c2b737
Compare
Hi @Enselic, if you do get time to look at this again that would be great but no worries there are lots of other issues to attend to currently. It will be nice for delta if it turns out to be possible to go in this direction because I'll be able to delete some vendored code and update highlighting assets simply by bumping the bat library version. |
@dandavison Sorry for letting you wait on this. I've had my plate full lately. I haven't had time to investigate this myself yet, so maybe I should just go ahead and ask instead: I don't fully understand why you can't use the existing API based around theme names, i.e. |
Hi @Enselic, no worries!
Sure, that's easy to explain. My motivation here is to use the bat library in delta. Delta is, like bat, a Rust application that uses syntect for highlighting. So I need the bat library to give me the syntect theme structs themselves, not just the names. The connection between delta and bat is:
The purpose of this PR is to alter the bat library so that a client such as delta can use the bat library for its collection of binary highlighting assets. |
Thanks for the explanation! That makes sense. If that is the case, isn't it enough to simply change
to
? That would enable you to get the syntect |
Yes, thank you @Enselic! You're right -- I think because delta had always used syntect's |
I'm in favor of this (now minimal) change. Especially since we warn in the documentation that the API of these internal modules is much more likely to change. Some or all of these modules might be removed in the future. |
I am also fine with this change as long as the API is only considered semi-stable, but I agree the disclaimer in the docs makes that clear. I think it would be good to repeat that disclaimer in the docs of the individual changed methods just to make sure people see them though. But it is not a super strong wish. @dandavison Can you also add an entry in CHANGELOG.md in the "bat as a library" section for this please? More info in https://github.com/sharkdp/bat/blob/master/CONTRIBUTING.md. Thanks! Apart from the above I consider this PR Approved 🎉 As a side-note, I have played around with the thought of having a The |
Thanks @sharkdp and @Enselic, I've add the Changelog entry.
What do you think about having a crate dedicated specifically to the collection of highlighting assets and the wrapping API for working with them? It's a very useful collection. (Are there syntect apps other than delta using them?) As a side effect I'm guessing you might appreciate not having all those submodules in your main repo. |
This has been requested a few times, and I agree that this would certainly be very useful. I have written down my thoughts on this here: #919 |
@dandavison We are currently experimenting with time based releases, and if everything goes as planned, the next release will be in April. Just to give you a sense of when the API will be available to delta. |
@dandavison @michaelblyons Heads-up that we will make a bat v0.19.1 release with this new API in the coming days. We want to keep projects that depend on bat happy. Waiting until April to make a release seems way too long in this case. :) |
Excellent, thanks a lot @Enselic. I'll make a delta release shortly afterwards. |
Released in https://crates.io/crates/bat/0.20.0 🎉 (Turned out we had a semver breaking change, so we had to do v0.20.0 rather than v0.19.1) |
Proof-of-principle draft PR allowing delta to replace vendored bat code with bat library usage.
See
#2026
dandavison/delta#903 (companion delta PR)