AMythicDev / minus

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

Calling page_all() twice panics #85

Closed jrb0001 closed 1 year ago

jrb0001 commented 1 year ago

Describe the bug It is currently not possible to show a second pager after the first (static) one finished.

To Reproduce

use minus::error::MinusError;

fn main() -> Result<(), MinusError> {
    for _ in 0..2 {
        let output = minus::Pager::new();

        output.set_exit_strategy(minus::ExitStrategy::PagerQuit)?;

        for i in 0..=100 {
            output.push_str(&format!("{}\n", i))?;
        }

        minus::page_all(output)?;
        }
    Ok(())
}

Expected behavior It is possible to show many pagers sequentially.

Desktop:

Additional context The changes from #82 are not complete. There is still one break each in the static/dynamic match which doesn't reset RUNMODE.

On the main branch, adding the missing reset leads to a deadlock. I think the dereferenced MutexGuard from the match is kept until the end of the match block. I didn't continue here because I ran into scrolling issues (#86).

Is there a reason why you need a Mutex? Otherwise atomics (for example crossbeam_utils::atomicAtomicCell) would be much easier to use for this.

AMythicDev commented 1 year ago

There are some extra break lines that got there probably because of some merge conflicts.

jrb0001 commented 1 year ago

Makes sense, but I still had to move the locking out of the match. PR will follow after I verified it in my application.

AMythicDev commented 1 year ago

I actually didn't knew about crossbeam_utils::atomics::AtomicCell so I just went ahead with parking_lot since I also needed to used it in other places. I will consider it in later phases.