From 619407eb548c7df56bc99b945338e9446f846fbb Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 14 Dec 2023 16:08:00 +0800 Subject: 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. --- test/functional/terminal/channel_spec.lua | 51 ++++++++++++++++++++++++++++ test/functional/terminal/scrollback_spec.lua | 22 ++++++------ 2 files changed, 62 insertions(+), 11 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/channel_spec.lua b/test/functional/terminal/channel_spec.lua index 6fb1a21561..b9abcd61c8 100644 --- a/test/functional/terminal/channel_spec.lua +++ b/test/functional/terminal/channel_spec.lua @@ -192,4 +192,55 @@ describe('no crash when TermOpen autocommand', function() ]]} assert_alive() end) + + it('nvim_open_term({force_crlf=true}) converts newlines', function() + local buf = meths.create_buf(false, true) + local win = meths.get_current_win() + local term = meths.open_term(buf, {force_crlf = true}) + screen:try_resize(8, 10) + meths.win_set_buf(win, buf) + meths.chan_send(term, 'here\nthere\nfoo\r\nbar\n\ntest') + screen:expect{grid=[[ + ^here | + there | + foo | + bar | + | + test | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + meths.chan_send(term, '\nfirst') + screen:expect{grid=[[ + ^here | + there | + foo | + bar | + | + test | + first | + {0:~ }| + {0:~ }| + | + ]]} + meths.buf_delete(buf, {force = true}) + buf = meths.create_buf(false, true) + term = meths.open_term(buf, {force_crlf = false}) + meths.win_set_buf(win, buf) + meths.chan_send(term, 'here\nthere') + screen:expect{grid=[[ + ^here | + there | + | + | + | + | + | + | + | + | + ]]} + end) end) diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index d2c636b03f..00104734ef 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -576,21 +576,21 @@ describe("pending scrollback line handling", function() ]] screen:expect [[ {1: 1 }^a | - {1: 2 } a | - {1: 3 } a | - {1: 4 } a | - {1: 5 } a | - {1: 6 } a | + {1: 2 }a | + {1: 3 }a | + {1: 4 }a | + {1: 5 }a | + {1: 6 }a | | ]] feed('G') screen:expect [[ - {1: 7 } a | - {1: 8 } a | - {1: 9 } a | - {1: 10 } a | - {1: 11 } a | - {1: 12 } ^a | + {1: 7 }a | + {1: 8 }a | + {1: 9 }a | + {1: 10 }a | + {1: 11 }a | + {1: 12 }^a | | ]] assert_alive() -- cgit