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

strip-ansi-escapes new release v0.1.2 is breaking reedline. #616

Closed
marcosfpr opened this issue Aug 8, 2023 · 9 comments · Fixed by #617
Closed

strip-ansi-escapes new release v0.1.2 is breaking reedline. #616

marcosfpr opened this issue Aug 8, 2023 · 9 comments · Fixed by #617
Labels
bug Something isn't working

Comments

@marcosfpr
Copy link

Platform macOS,
Terminal software zsh

With the new strip-ansi-escapes release luser/strip-ansi-escapes#15 , reedline is not compiling in my project.

Steps to reproduce

  1. Cargo.toml:
[dependencies]
reedline = "0.22.0"
  1. I'm getting the following error when compiling reedline on a MacOS M2:
error[E0599]: no method named `map_err` found for struct `Vec<u8>` in the current scope
  
39 | /     strip_ansi_escapes::strip(string)
40 | |         .map_err(|_| ())
   | |         -^^^^^^^ method not found in `Vec<u8>`
   | |_________|
   | 

Am I doing something wrong? Thanks :)

@marcosfpr marcosfpr added the bug Something isn't working label Aug 8, 2023
@amtoine
Copy link
Member

amtoine commented Aug 8, 2023

not knowing a lot about Reedline, what is the project and what is the command you are running?

that might help people reproduce the error and investigate 😋

@marcosfpr
Copy link
Author

Actually I'm just trying to compile an empty project.

Just creating something like cargo new --lib test_reedline, adding the dependency and running cargo c.

@amtoine
Copy link
Member

amtoine commented Aug 8, 2023

oh yeah i can reproduce with

cargo new --lib /tmp/test_reedline
cd /tmp/test_reedline
cargo add [email protected]
cargo check

@fdncred
Copy link
Contributor

fdncred commented Aug 8, 2023

Ah, they changed the API.

Version 0.1.1

/// Strip ANSI escapes from `data` and return the remaining bytes as a `Vec<u8>`.
///
/// See [the module documentation][mod] for an example.
///
/// [mod]: index.html
pub fn strip<T>(data: T) -> io::Result<Vec<u8>>
where
    T: AsRef<[u8]>,
{
    let c = Cursor::new(Vec::new());
    let mut writer = Writer::new(c);
    writer.write_all(data.as_ref())?;
    Ok(writer.into_inner()?.into_inner())
}

Version 0.1.2

/// Strip ANSI escapes from `data` and return the remaining bytes as a `Vec<u8>`.
///
/// See [the module documentation][mod] for an example.
///
/// [mod]: index.html
pub fn strip<T>(data: T) -> Vec<u8>
where
    T: AsRef<[u8]>,
{
    fn strip_impl(data: &[u8]) -> io::Result<Vec<u8>> {
        let c = Cursor::new(Vec::new());
        let mut writer = Writer::new(c);
        writer.write_all(data.as_ref())?;
        Ok(writer.into_inner()?.into_inner())
    }

    strip_impl(data.as_ref()).expect("writing to a Cursor<Vec<u8>> cannot fail")
}

@fdncred
Copy link
Contributor

fdncred commented Aug 8, 2023

I think this will fix the code in reedline.

Old code

/// Returns string with the ANSI escape codes removed
///
/// If parsing fails silently returns the input string
pub(crate) fn strip_ansi(string: &str) -> String {
    strip_ansi_escapes::strip(string)
        .map_err(|_| ())
        .and_then(|x| String::from_utf8(x).map_err(|_| ()))
        .unwrap_or_else(|_| string.to_owned())
}

New

/// Returns string with the ANSI escape codes removed
///
/// If parsing fails silently returns the input string
pub(crate) fn strip_ansi(string: &str) -> String {
    String::from_utf8(strip_ansi_escapes::strip(string))
        .map_err(|_| ())
        .unwrap_or_else(|_| string.to_owned())
}

@marcosfpr
Copy link
Author

Thank you @fdncred!!!! Can we release a hotfix for that?

@fdncred
Copy link
Contributor

fdncred commented Aug 8, 2023

You're welcome. I don't do much here without @sholderbach's blessing.

@sholderbach
Copy link
Member

Thanks for the heads up @marcosfpr and thanks for the quick fix @fdncred!

Not sure if a hotfix will be particularly long lived (unless you use pinned versions with --locked) as it is likely this semver-breaking version of strip-ansi-escapes will probably have to be yanked, as it also affects a bunch of other crates. luser/strip-ansi-escapes#17

I will land the API change already, and have a look if there are developments on the strip-ansi-escapes side. If they soon release the 0.2.0 version I will publish a point release for that.

@sholderbach
Copy link
Member

As the problematic version is now yanked this should be resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants