Canop / termimad

A library to display rich (Markdown) snippets and texts in a rust terminal application
MIT License
914 stars 31 forks source link

Crossterm 0.25.0 breaking changes #35

Closed fangpinsern closed 9 months ago

fangpinsern commented 2 years ago

When using crossterm 0.25.0 with termimad 0.20.3, I get the following error when I followed the code example in the docs:

error[E0308]: mismatched types
 --> src/theme.rs:9:46
  |
9 |     skin.strikeout = CompoundStyle::new(Some(Red), None, Bold.into());
  |                                              ^^^ expected enum `crossterm::style::types::color::Color`, found enum `Color`
  |
  = note: perhaps two different versions of crate `crossterm` are being used?

error[E0277]: the trait bound `crossterm::style::attributes::Attributes: From<Attribute>` is not satisfied
 --> src/theme.rs:9:63
  |
9 |     skin.strikeout = CompoundStyle::new(Some(Red), None, Bold.into());
  |                                                               ^^^^ the trait `From<Attribute>` is not implemented for `crossterm::style::attributes::Attributes`
  |
  = help: the following implementations were found:
            <crossterm::style::attributes::Attributes as From<&[crossterm::style::types::attribute::Attribute]>>
            <crossterm::style::attributes::Attributes as From<crossterm::style::types::attribute::Attribute>>
  = note: required because of the requirements on the impl of `Into<crossterm::style::attributes::Attributes>` for `Attribute`

From this answer, it seems there there is a breaking change between crossterm 0.23 and crossterm 0.25. https://stackoverflow.com/questions/74141606/cannot-compile-rust-program-due-to-e0308-error/74144038#74144038

Is it possible to state what version of crossterm supported by termimad or update the library to accept the newest version of crossterm?

Canop commented 2 years ago

Libraries whose version are in 0.x have an unstable API. This is the case for Crossterm, which had breaking changes in 0.24 and 0.25. When Crossterm changes, it's sometimes easy to update the libraries using them. It sometimes isn't. Right now, Crossterm 0.25 has major breaking changes and may not bring immediate benefits. So I'm currently postponing an update which will force crossterm based libraries to change their API too. Right now, I'll add a compatibility note in the README and we'll keep this issue open until Termimad is changed to be compatible with 0.25 (or more recent).

fangpinsern commented 2 years ago

Sounds good thanks!!

EverlastingBugstopper commented 1 year ago

Since crossterm is needed for styling - would you ever consider re-exporting the styles directly? You could potentially gate this behind a feature flag (which I would argue should be enabled by default). This error message (mismatched versions) is the most frequent error I encounter with this crate, and this crate is the only thing I need to use crossterm directly for. It would be great if I only had to specify one dependency instead of two in order to use this crate!

Canop commented 9 months ago

The new release of Termimad, version 0.28, reexports crossterm 0.27.

To be sure of the compatibility, don't import crossterm directly but use termimad::crossterm.