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

Cannot clear highlights in bat::PrettyPrinter instance #1919

Closed
rhysd opened this issue Oct 23, 2021 · 1 comment · Fixed by #1920
Closed

Cannot clear highlights in bat::PrettyPrinter instance #1919

rhysd opened this issue Oct 23, 2021 · 1 comment · Fixed by #1920
Labels
bug Something isn't working

Comments

@rhysd
Copy link
Contributor

rhysd commented Oct 23, 2021

Describe the bug you encountered:

Let's say we have the following code:

use bat::PrettyPrinter;

let targets: (PathBuf, Vec<(usize, usize)>) = vec![];

let mut pp = PrettyPrinter::new();
for (path, ranges) in targets.iter() {
    pp.input_file(path);
    for (start, end) in ranges.iter() {
        pp.highlight_range(*start, *end);
    }

    // This clears inputs, but does not clear highlights
    pp.print().unwrap();
}

Since there are multiple files with different highlight ranges, I want to print each files with different ranges. However, currently there is no way to clear highlights in bat::PrettyPrinter instance.

Creating bat::PrettyPrinter instance for each file is an option. However it is much slower because bat::PrettyPrinter::new deserializes binary assets and it is time consuming.

What did you expect to happen instead?

I'd like bat::PrettyPrinter to provide some API to clear highlights.

How did you install bat?

[dependencies]
bat = { version = "0.18.3", default-features = false }

in my project's Cargo.toml.


bat version and environment

  • bat: 0.18.3
  • OS: macOS 10.15
  • Rust: 1.56
@rhysd rhysd added the bug Something isn't working label Oct 23, 2021
rhysd added a commit to rhysd/bat that referenced this issue Oct 23, 2021
@sharkdp sharkdp added this to the v0.19 milestone Nov 22, 2021
@Enselic Enselic removed this from the v0.19 milestone Mar 3, 2022
@Enselic
Copy link
Collaborator

Enselic commented Jun 18, 2022

Creating bat::PrettyPrinter instance for each file is an option. However it is much slower because bat::PrettyPrinter::new deserializes binary assets and it is time consuming.

Just wanted to add a remark: This should be be much less of a problem now that syntaxes are lazy-loaded.

rhysd added a commit to rhysd/bat that referenced this issue Sep 5, 2022
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.

3 participants