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

Inconsistant formatting with wrapped text #137

Open
Sam-Sims opened this issue Apr 10, 2024 · 1 comment
Open

Inconsistant formatting with wrapped text #137

Sam-Sims opened this issue Apr 10, 2024 · 1 comment

Comments

@Sam-Sims
Copy link

Describe the bug
First of all, great performance improvements in the latest update - actually made me revist a programme I was working on. However I have come across a bug regarding textwrapping and being redrawn to the terminal.

Essentially when a string is formatted (for example with a colour) and that text is wrapped, if you scroll past it (so it isnt rendered) and then scroll back up (to re-render it) the wrapped portion of the string loses its formatting.

The loss of formatting occurs when scrolling with mouse wheel or using the arrow keys for navigation. However, when using the Page Up and Page Down keys, the formatting is preserved. The behavior with the scroll wheel is inconsistent - sometimes the formatting remains intact, while other times it gets lost. In contrast, the issue consistently arises when using the arrow keys.

In addition the formatting seems inconsistant when using the arrow keys even without reloading - occasionally the wrapped text wont have the formatting applied at all, again using PgUp/PgDown doesnt have this issue. I couldnt work out a cause for this.

To Reproduce
An example to reproduce below (ensure terminal is narrow enough to wrap the highlighted text)

use std::thread::spawn;
use minus::{Pager, dynamic_paging};
use crossterm::style::{StyledContent, Stylize};

fn main() {
    let mut pager = Pager::new();
    let pager2 = pager.clone();
    let pager_thread = spawn(move || dynamic_paging(pager2));

    // Create formatted string
    let string_to_print = format!("{}{}{}", "1".repeat(110), "2".repeat(50), "\n\n");
    let search = "1111111112222";
    let styled_sequence = string_to_print.replace(search, &search.dark_yellow().to_string());

    // It also happens using terminal escape codes (see below)
    //let styled_sequence = string_to_print.replace(search, &format!("\x1b[33m{}\x1b[0m", search));

    pager.push_str(styled_sequence.repeat(100)).unwrap();
    pager_thread.join().unwrap();
}

Expected behavior
Formatting is preserved when wrapped and reloaded after scrolling past.

Screenshots
As you can see the first 4 rows have been scrolled past, and reloaded and they lose the yellow formatting:
image

Desktop:

  • WSL2 Ubuntu 22:04
  • zsh
  • 5.6.1

Additional context
I have also replicated this issue on native Ubuntu 23

@AMythicDev
Copy link
Owner

First of all, great performance improvements in the latest update - actually made me revist a programme.

Thanks! Future releases will also have a lot of work on more performance.

Unfortunately I am not getting enough time right now to actively fix these types of bugs that require a proper debugging session because I am preparing for my exams in May. I will come back to this once my exams are over and life is a bit sorted :). I hope you will bear me.

In the meantime if you want to contribute, feel free to throw in a PR. In case you need help, ask it over on Discord. I regularly check in there.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants