Canop / termimad

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

Panic from `print_text` #22

Closed samtay closed 4 years ago

samtay commented 4 years ago

Someone has observed thread 'main' panicked at 'attempt to subtract with overflow' coming from a skin.print_text call (ref samtay/so#8), and also found that such panic goes away when using skin.print_inline. Unfortunately I couldn't repo this myself, but the relevant details from that issue are:

Note the markdown input is quite large, so I put it in a gist. I also embedded it within the ./examples/text/main.rs file so that it would be easier to run.

EDIT: I was able to repro this. At terminal width 112 there is no panic. If the terminal width is greater than or equal to 117, you can observe this panic.

I think if you make sure your terminal width is that wide (e.g. go full screen), and run this:

cd /path/to/termimad
curl -o "examples/text/main.rs" "https://gist.githubusercontent.com/samtay/cf9d1b8c0c7935baf6f6971101bd567e/raw/dff5e762f9a56f76aa64e9c61b57311c42c7a0f0/example-panic.rs"
RUST_BACKTRACE=1 cargo run --example text

you should be able to observe it.

Canop commented 4 years ago

I do reproduce it.

Smaller example:

use std::io::Write;
use termimad::*;

static MD: &str = r#"
Note that the "before" code is basically the [implementation of today's `poll_fn` function](https://github.com/rust-lang-nursery/futures-rs/blob/0.3.1/futures-util/src/future/poll_fn.rs#L48-L56)
"#;

fn main() {
    let skin = MadSkin::default();
    skin.print_text(MD);
}
Canop commented 4 years ago

This should have been fixed. Can you please confirm it's OK @samtay ?

samtay commented 4 years ago

Yes, I just tried out master and it's working on my end. Thanks for such a quick fix!