gnvim icon indicating copy to clipboard operation
gnvim copied to clipboard

Support input piping

Open yodahuang opened this issue 6 years ago • 2 comments

Currently,

echo "foo" | gnvim

yields a blank document, while

echo "foo" | gnvim -

returns an error saying thread 'main' panicked at 'Error sending message: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', src/libcore/result.rs:999:5

It would be nice if we could have input piping / reading from stdin work properly.

yodahuang avatar Jul 22 '19 23:07 yodahuang

Something along these lines (though more polished: not just blindly unwrapping, not causing infinite loop if no input, etc.) would probably work (it does get the piped info):

    let stdin = std::io::stdin();
    for line in stdin.lock().lines() {
        // Pseudocode
        neovim_println!("{}", line);
    }

There's probably a better way, but even if that's the case we still need a way to push the text to the starting neovim buffer, which I'm not sure how to do ATM (neovim_println! isn't actually a thing unfortunately).

As a side note, neovim-gtk does support this (from my test), while gonvim does not (latest release).

smolck avatar Jul 23 '19 03:07 smolck

As it happens, we are planning to add nvim core support for this. Because with https://github.com/neovim/neovim/pull/10071 even TUI will use the "remote UI" protocol. Probably we will allow nvim --embed to take an extra fd (like fd=3), and some API function nvim_load_stdin(fd) (to be called before ui_attach) to ask nvim to load the "stdin file" from this fd instead.

bfredl avatar Jul 23 '19 07:07 bfredl

Supported now on unix targets.

vhakulinen avatar Nov 29 '22 19:11 vhakulinen