diff options
author | Raphael <glephunter@gmail.com> | 2023-12-14 16:08:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 16:08:00 +0800 |
commit | 619407eb548c7df56bc99b945338e9446f846fbb (patch) | |
tree | 7e3b4e11f467c32de90cdc1afa7de08cc725c4e7 /src/nvim/terminal.c | |
parent | 36552adb39edff2d909743f16c1f061bc74b5c4e (diff) | |
download | rneovim-619407eb548c7df56bc99b945338e9446f846fbb.tar.gz rneovim-619407eb548c7df56bc99b945338e9446f846fbb.tar.bz2 rneovim-619407eb548c7df56bc99b945338e9446f846fbb.zip |
feat(nvim_open_term): convert LF => CRLF (#26384)
Problem:
Unlike termopen(), nvim_open_term() PTYs do not carriage-return the
cursor on newline ("\n") input.
nvim --clean
:let chan_id = nvim_open_term(1, {})
:call chansend(chan_id, ["here", "are", "some", "lines"])
Actual behavior:
here
are
some
lines
Expected behaviour:
here
are
some
lines
Solution:
Add `force_crlf` option, and enable it by default.
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r-- | src/nvim/terminal.c | 18 |
1 files changed, 17 insertions, 1 deletions
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); } |