-
Notifications
You must be signed in to change notification settings - Fork 64
Make rendering color agnostic #387
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
base: master
Are you sure you want to change the base?
Conversation
Very cool! I like the HTML backend, can see myself using that. Had a quick look, will have a closer look later in week. Before it is merged I think it needs some fixes after running |
im trying to run the tests and im getting an error in anyhow, error[E0599]: no method named `backtrace` found for reference `&(dyn std::error::Error + Send + Sync + 'st
atic)` in the current scope
--> /home/urisig/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.0/src/error.rs:159:44
|
159 | .or_else(|| self.inner.error().backtrace())
| ^^^^^^^^^ method not found in `&dyn Error + Send + Sync``` |
Oooh I have run into that issue before... I don't think it was on this repository and I cannot remember how I fixed it. I can only think: double check you are on the latest and run |
tests are now passing. should this be locked behind the termcolor feature just like before? I think i might be able to get this to work without it. |
@kaleidawave the pr is ready to review. Although im not quite sure about the changes to the api yet, the emit function requires a bit more boilerplate to use now. Im also thinking of making the html renderer part of the crate, its a very simple renderer that can be quite useful |
@@ -104,51 +108,51 @@ pub enum DisplayStyle { | |||
pub struct Styles { |
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.
Is there a reason why these fields are no longer public?
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 used it to refactor and forgot to make it public, they definitely should be public
|
||
#[cfg(feature = "termcolor")] | ||
#[cfg(feature = "std")] | ||
impl<'a, W: WriteColor> io::Write for StylesWriter<'a, W> { |
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.
Nice! So this impl
ensures all existing uses will not break and this update will be backwards compatible?
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.
nope, you will have to create a StylesWriter instead of a ColorWriter, but its just a two line change with
let styles = Styles::default();
let styles_writer = StylesWriter::new(writer, &styles);
.unwrap(); | ||
let style = codespan_reporting::term::Styles::default(); | ||
let color_writer = StandardStream::stdout(ColorChoice::Auto); | ||
let mut writer = codespan_reporting::term::StylesWriter::new(color_writer.lock(), &style); |
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.
Is there a reason why the writer has changed. StandardStream::stdout(ColorChoice::Auto)
should still work right? Want to make sure that it doesn't create breaking changes
Looks good, have a few queries but after they are resolved and I have tested this on one of my own projects I will merge. |
Resolves #386
This adds a new
WriteStyle
trait for styling that replaces WriteColor.Right now, the only public APIs I’ve changed are the ones for
Config
andemit
: I removedStyle
fromConfig
(because a renderer doesn’t always need one) and added astyle
parameter toemit
.Using the API is very simple, just implement the
WriteStyle
trait, and then pass your writer to the renderer. I’ve implemented a minimal HTML backend here, based on readme_preview.rs.