Render non-terminating commands for `--preview` like in fzf
Hello, I'd like to be able to run something like cat hosts.txt | sk --preview 'ping {}' and having the preview show a live preview of that command the same way as fzf.
Right now sk is waiting for the command to finish, while fzf with cat hosts.txt | fzf --preview 'ping {}' streams the command's output as it writes.
This is what the previous fzf command looks like:
And this the sk command (it gets stuck and doesn't show anything):
In fact, and this seems to be a bug, I cannot ctrl-c or ctrl-z sk when running this example. I need to kill it to get the control of my terminal back.
It'd be nice to have this feature also in skim's ItemPreview (this is where I actually need it). Maybe the implementation could look like this, since I understand skim cares about performance:
enum ItemPreview<T: IntoIterator<Item = u8>> {
/// execute the command and print the command's output
Command(T),
/// Display the prepared text(lines)
Text(T),
// ...
}I know it's ugly with that generic T, but it'd let the user choose whether to build the preview either as a Vec<u8> or a std::sync::mpsc::Receiver<u8>. The latter would let you build the live preview I was talking about.
It could also be considered to make ItemPreview generic over tokio-stream's Stream trait instead for async iterators, especially given that this crate already uses tokio, but I leave that up to the maintainers.
Source: skim-rs/skim