diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/keysets_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 3 | ||||
-rw-r--r-- | src/nvim/channel.c | 1 | ||||
-rw-r--r-- | src/nvim/terminal.c | 18 | ||||
-rw-r--r-- | src/nvim/terminal.h | 1 |
5 files changed, 22 insertions, 2 deletions
diff --git a/src/nvim/api/keysets_defs.h b/src/nvim/api/keysets_defs.h index d1cbe43de0..c0daa0ca74 100644 --- a/src/nvim/api/keysets_defs.h +++ b/src/nvim/api/keysets_defs.h @@ -344,4 +344,5 @@ typedef struct { typedef struct { OptionalKeys is_set__open_term_; LuaRef on_input; + Boolean force_crlf; } Dict(open_term); diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a52d7493e3..2f3d527b9e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -985,6 +985,7 @@ fail: /// as a "\r", not as a "\n". |textlock| applies. It is possible /// to call |nvim_chan_send()| directly in the callback however. /// ["input", term, bufnr, data] +/// - force_crlf: (boolean, default true) Convert "\n" to "\r\n". /// @param[out] err Error details, if any /// @return Channel id, or 0 on error Integer nvim_open_term(Buffer buffer, Dict(open_term) *opts, Error *err) @@ -1002,7 +1003,6 @@ Integer nvim_open_term(Buffer buffer, Dict(open_term) *opts, Error *err) } LuaRef cb = LUA_NOREF; - if (HAS_KEY(opts, open_term, on_input)) { cb = opts->on_input; opts->on_input = LUA_NOREF; @@ -1020,6 +1020,7 @@ Integer nvim_open_term(Buffer buffer, Dict(open_term) *opts, Error *err) .write_cb = term_write, .resize_cb = term_resize, .close_cb = term_close, + .force_crlf = GET_BOOL_OR_TRUE(opts, open_term, force_crlf), }; channel_incref(chan); terminal_open(&chan->term, buf, topts); diff --git a/src/nvim/channel.c b/src/nvim/channel.c index ca8cbed8f9..fb4711f7d9 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -801,6 +801,7 @@ void channel_terminal_open(buf_T *buf, Channel *chan) .write_cb = term_write, .resize_cb = term_resize, .close_cb = term_close, + .force_crlf = false, }; buf->b_p_channel = (OptInt)chan->id; // 'channel' option channel_incref(chan); diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index af9693c4b0..3b70ee922a 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -43,6 +43,7 @@ #include <vterm.h> #include <vterm_keycodes.h> +#include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" @@ -80,6 +81,7 @@ #include "nvim/optionstr.h" #include "nvim/pos_defs.h" #include "nvim/state.h" +#include "nvim/strings.h" #include "nvim/terminal.h" #include "nvim/types_defs.h" #include "nvim/ui.h" @@ -786,7 +788,21 @@ void terminal_receive(Terminal *term, const char *data, size_t len) return; } - vterm_input_write(term->vt, data, len); + if (term->opts.force_crlf) { + StringBuilder crlf_data = KV_INITIAL_VALUE; + + for (size_t i = 0; i < len; i++) { + if (data[i] == '\n' && (i == 0 || (i > 0 && data[i - 1] != '\r'))) { + kv_push(crlf_data, '\r'); + } + kv_push(crlf_data, data[i]); + } + + vterm_input_write(term->vt, crlf_data.items, kv_size(crlf_data)); + kv_destroy(crlf_data); + } else { + vterm_input_write(term->vt, data, len); + } vterm_screen_flush_damage(term->vts); } diff --git a/src/nvim/terminal.h b/src/nvim/terminal.h index db62bd2a5b..ffa97f17b2 100644 --- a/src/nvim/terminal.h +++ b/src/nvim/terminal.h @@ -16,6 +16,7 @@ typedef struct { terminal_write_cb write_cb; terminal_resize_cb resize_cb; terminal_close_cb close_cb; + bool force_crlf; } TerminalOptions; #ifdef INCLUDE_GENERATED_DECLARATIONS |