chrisvest / xxv

The XXV visual hex viewer for the terminal.
https://chrisvest.github.io/xxv/
85 stars 5 forks source link

Panic when reading from fifo or named pipe #20

Open lilyball opened 4 years ago

lilyball commented 4 years ago

If I pass xxv a fifo or a named pipe (such as /dev/stdin) it promptly panics, leaving my terminal in a bad state.


Panic in xxv 0.1.2, 2020-05-20T11:03:25-07:00.
System: macos (unix), x86_64.
Location: src/hex_view.rs:397:13.

   0:        0x10628140d - backtrace::capture::Backtrace::new::ha9f89a6fa35894cc
   1:        0x10626fffb - xxv::panic_hook::install::{{closure}}::h8cc3772e827e167c
   2:        0x1062aeca4 - std::panicking::rust_panic_with_hook::he4f5d8b43533efd5
   3:        0x1062aea69 - rust_begin_unwind
   4:        0x106285e4f - core::panicking::panic_fmt::h3559129da805eab4
   5:        0x106286025 - core::result::unwrap_failed::h170de03e7ee26a1a
   6:        0x10625a28d - cursive::view::view_wrapper::<impl cursive::view::view_trait::View for T>::layout::hd14996d839b09c6c
chrisvest commented 4 years ago

Right... we can't fseek a pipe.

Currently things work by seeking each line in the window projected over the file. That's how XXV can navigate anywhere in arbitrarily large files.

For something like stdin, we can't navigate and new data can come along all the time. Would it be reasonable to funnel the data to a temporary file in a background thread, and then place the normal view on that file?

lilyball commented 4 years ago

At a bare minimum, we shouldn't panic in a way that puts the terminal in a bad state. The minimal fix here is detecting that the file is a pipe and gracefully erroring.

But yes, I think a better long-term fix is to funnel the data into a temporary file and seek on that. I'd say maybe seeking on a memory buffer except then you have to deal with dumping it to disk once it gets sufficiently large, so maybe just using a temporary file always is a good idea.