AMythicDev / minus

An asynchronous, runtime data feedable terminal paging library for Rust
https://crates.io/crates/minus/
Apache License 2.0
317 stars 23 forks source link

Horizontal scroll error if there is no char boundary check #143

Open zhangzhuang15 opened 2 months ago

zhangzhuang15 commented 2 months ago

Describe the bug If there is unnormal char in content, such as "▲" which takes up 3 bytes, when scroll to right horizontally by ">" button, process will exit with error like:

thread 'main' panicked at /Users/zhangzhuang/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/minus-5.6.1/src/core/init.rs:198:12:
called `Result::unwrap()` on an `Err` value: Any { .. }

To Reproduce

use minus::Pager;
use std::fmt::Write;
fn main() {
    let mut pager = Pager::new();
    let _ = pager.horizontal_scroll(true);

    let s = "
    fdafadfafasdfasfa fdafa fdaf fdf fdfs fdaf  fdf  fdf f af  sdfasdf fdafaf ▲fdfasdfsa
    fadfadf fdaf fdaf  ffadfad f f fd fdf
    fdfadf f fdaf  dsfdafa
     fdsfasdf  ▲
    ";
    let _ = writeln!(pager, "{}", s);
    let _ = writeln!(pager, "{}", s);
    let _ = writeln!(pager, "{}", s);
    let _ = writeln!(pager, "{}", s);
    let _ = writeln!(pager, "{}", s);
    let _ = writeln!(pager, "{}", s);
    minus::page_all(pager);
}
[dependencies]
minus = { version = "5.6.1", features = ["static_output"] }

run cargo run, then press ">" to scroll right, when " ▲" touches the left side of terminal, there will be an error.

Expected behavior No error, process doesn't exit.

Screenshots

Desktop:

Additional context

zhangzhuang15 commented 2 months ago

I' m working on this issue.