diff options
author | hlpr98 <hlpr98@gmail.com> | 2022-04-16 14:46:20 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-05-02 16:27:29 +0200 |
commit | 619c8f4b9143e4dea0fb967ccdce594e14956ed3 (patch) | |
tree | 2c503c7f5e36b788ec250a8a8fb33478c090ff11 /src/nvim/api/vim.c | |
parent | af53fa06636586511a6208094332d2e1245ab2a0 (diff) | |
download | rneovim-619c8f4b9143e4dea0fb967ccdce594e14956ed3.tar.gz rneovim-619c8f4b9143e4dea0fb967ccdce594e14956ed3.tar.bz2 rneovim-619c8f4b9143e4dea0fb967ccdce594e14956ed3.zip |
feat(api): support handling stdin stream in remote ui
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 061653c5af..9c34c912c0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2661,3 +2661,35 @@ end: xfree(cmdline); return result; } + +/// Invokes the nvim server to read from stdin when it is not a tty +/// +/// It enables functionalities like: +/// - echo "1f u c4n r34d th1s u r34lly n33d t0 g37 r357"| nvim - +/// - cat path/to/a/file | nvim - +/// It has to be called before |nvim_ui_attach()| is called in order +/// to ensure proper functioning. +/// +/// @param channel_id: The channel id of the GUI-client +/// @param filedesc: The file descriptor of the GUI-client process' stdin +/// @param implicit: Tells if read_stdin call is implicit. +/// i.e for cases like `echo xxx | nvim` +/// @param[out] err Error details, if any +void nvim_read_stdin(uint64_t channel_id, Integer filedesc, Error *err) +FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +{ + if (starting != NO_SCREEN) { + api_set_error(err, kErrorTypeValidation, + "nvim_read_stdin must be called before nvim_ui_attach"); + return; + } + if (filedesc < 0) { + api_set_error(err, kErrorTypeValidation, + "file descriptor must be non-negative"); + return; + } + + stdin_filedesc = (int)filedesc; + implicit_readstdin = implicit; + return; +} |