From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/terminal.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index a52a34cd66..fca8515fab 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -82,7 +82,6 @@ #include "nvim/option.h" #include "nvim/optionstr.h" #include "nvim/pos.h" -#include "nvim/screen.h" #include "nvim/state.h" #include "nvim/terminal.h" #include "nvim/types.h" -- cgit From 8786b2066d39e45295eacfe7b10263af4a330f2e Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Sun, 19 Mar 2023 23:23:34 +0600 Subject: fix: pasting in terminal buffer on windows #22566 Problem: On Windows, pasting multiple lines on a terminal buffer cause all the lines to appear on the same line, i.e., the line breaks are lost. Cause: Windows shells expect "\r\n" as line break but "terminal_paste" function uses "\n". Solution: Use "\r\n" as line break for pasting in terminal buffer on Windows. Note: Although this issue was reported with powershell set as 'shell', it occurs in cmd too. Fixes #14621 --- src/nvim/terminal.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index fca8515fab..76fa3049f6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -723,7 +723,11 @@ void terminal_paste(long count, char **y_array, size_t y_size) for (size_t j = 0; j < y_size; j++) { if (j) { // terminate the previous line +#ifdef MSWIN + terminal_send(curbuf->terminal, "\r\n", 2); +#else terminal_send(curbuf->terminal, "\n", 1); +#endif } size_t len = strlen(y_array[j]); if (len > buff_len) { -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/terminal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 76fa3049f6..c774dbe384 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -896,13 +896,13 @@ static int term_moverect(VTermRect dest, VTermRect src, void *data) return 1; } -static int term_movecursor(VTermPos new, VTermPos old, int visible, void *data) +static int term_movecursor(VTermPos new_pos, VTermPos old_pos, int visible, void *data) { Terminal *term = data; - term->cursor.row = new.row; - term->cursor.col = new.col; - invalidate_terminal(term, old.row, old.row + 1); - invalidate_terminal(term, new.row, new.row + 1); + term->cursor.row = new_pos.row; + term->cursor.col = new_pos.col; + invalidate_terminal(term, old_pos.row, old_pos.row + 1); + invalidate_terminal(term, new_pos.row, new_pos.row + 1); return 1; } -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/terminal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index c774dbe384..0686305d02 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -680,7 +680,7 @@ void terminal_send(Terminal *term, char *data, size_t size) static bool is_filter_char(int c) { - unsigned int flag = 0; + unsigned flag = 0; switch (c) { case 0x08: flag = TPF_BS; @@ -839,7 +839,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int *te | (cell.attrs.italic ? HL_ITALIC : 0) | (cell.attrs.reverse ? HL_INVERSE : 0) | get_underline_hl_flag(cell.attrs) - | (cell.attrs.strike ? HL_STRIKETHROUGH: 0) + | (cell.attrs.strike ? HL_STRIKETHROUGH : 0) | ((fg_indexed && !fg_set) ? HL_FG_INDEXED : 0) | ((bg_indexed && !bg_set) ? HL_BG_INDEXED : 0); -- cgit From 5ac2e47acc999472042df4f10f8f7b5ffa72ba3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 17:42:14 +0800 Subject: fix(redo): make redo of Lua mappings in op-pending mode work (#23566) --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 0686305d02..0b0e321d8c 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -596,7 +596,7 @@ static int terminal_execute(VimState *state, int key) break; case K_LUA: - map_execute_lua(); + map_execute_lua(false); break; case Ctrl_N: -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/terminal.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 0b0e321d8c..62a2d1b6e6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -169,7 +169,7 @@ static VTermScreenCallbacks vterm_screen_callbacks = { .sb_popline = term_sb_pop, }; -static PMap(ptr_t) invalidated_terminals = MAP_INIT; +static Set(ptr_t) invalidated_terminals = SET_INIT; void terminal_init(void) { @@ -183,10 +183,10 @@ void terminal_teardown(void) time_watcher_stop(&refresh_timer); multiqueue_free(refresh_timer.events); time_watcher_close(&refresh_timer, NULL); - pmap_destroy(ptr_t)(&invalidated_terminals); + set_destroy(ptr_t, &invalidated_terminals); // terminal_destroy might be called after terminal_teardown is invoked // make sure it is in an empty, valid state - pmap_init(ptr_t, &invalidated_terminals); + invalidated_terminals = (Set(ptr_t)) SET_INIT; } static void term_output_callback(const char *s, size_t len, void *user_data) @@ -652,12 +652,12 @@ void terminal_destroy(Terminal **termpp) } if (!term->refcount) { - if (pmap_has(ptr_t)(&invalidated_terminals, term)) { + if (set_has(ptr_t, &invalidated_terminals, term)) { // flush any pending changes to the buffer block_autocmds(); refresh_terminal(term); unblock_autocmds(); - pmap_del(ptr_t)(&invalidated_terminals, term); + set_del(ptr_t, &invalidated_terminals, term); } for (size_t i = 0; i < term->sb_current; i++) { xfree(term->sb_buffer[i]); @@ -1027,7 +1027,7 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data) } memcpy(sbrow->cells, cells, sizeof(cells[0]) * c); - pmap_put(ptr_t)(&invalidated_terminals, term, NULL); + set_put(ptr_t, &invalidated_terminals, term); return 1; } @@ -1068,7 +1068,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data) } xfree(sbrow); - pmap_put(ptr_t)(&invalidated_terminals, term, NULL); + set_put(ptr_t, &invalidated_terminals, term); return 1; } @@ -1524,7 +1524,7 @@ static void invalidate_terminal(Terminal *term, int start_row, int end_row) term->invalid_end = MAX(term->invalid_end, end_row); } - pmap_put(ptr_t)(&invalidated_terminals, term, NULL); + set_put(ptr_t, &invalidated_terminals, term); if (!refresh_pending) { time_watcher_start(&refresh_timer, refresh_timer_cb, REFRESH_DELAY, 0); refresh_pending = true; @@ -1567,10 +1567,10 @@ static void refresh_timer_cb(TimeWatcher *watcher, void *data) void *stub; (void)(stub); // don't process autocommands while updating terminal buffers block_autocmds(); - map_foreach(&invalidated_terminals, term, stub, { + set_foreach(&invalidated_terminals, term, { refresh_terminal(term); }); - pmap_clear(ptr_t)(&invalidated_terminals); + set_clear(ptr_t, &invalidated_terminals); unblock_autocmds(); } -- cgit From c855eee919f2d4edc9b9fa91b277454290fbabfe Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 24 May 2023 10:04:49 +0200 Subject: feat(term): enable reflow by default (#21124) libvterm v0.3 supports reflow of terminal buffer when Nvim is resized Since v0.3 is now a required dependency, enable it by default to find (and fix) possible issues. Note: Neovim's scrollback buffer does not support reflow (yet), so lines vanishing into the buffer due to a too small window will be restored without reflow. --- src/nvim/terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 62a2d1b6e6..792071963d 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -220,6 +220,7 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) // Set up screen rv->vts = vterm_obtain_screen(rv->vt); vterm_screen_enable_altscreen(rv->vts, true); + vterm_screen_enable_reflow(rv->vts, true); // delete empty lines at the end of the buffer vterm_screen_set_callbacks(rv->vts, &vterm_screen_callbacks, rv); vterm_screen_set_damage_merge(rv->vts, VTERM_DAMAGE_SCROLL); -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/terminal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 792071963d..676ac954f7 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -235,7 +235,7 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) aucmd_prepbuf(&aco, buf); refresh_screen(rv, buf); - set_option_value("buftype", 0, "terminal", OPT_LOCAL); // -V666 + set_option_value("buftype", STATIC_CSTR_AS_OPTVAL("terminal"), OPT_LOCAL); // -V666 // Default settings for terminal buffers buf->b_p_ma = false; // 'nomodifiable' @@ -243,8 +243,8 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) buf->b_p_scbk = // 'scrollback' (initialize local from global) (p_scbk < 0) ? 10000 : MAX(1, p_scbk); buf->b_p_tw = 0; // 'textwidth' - set_option_value("wrap", false, NULL, OPT_LOCAL); - set_option_value("list", false, NULL, OPT_LOCAL); + set_option_value("wrap", BOOLEAN_OPTVAL(false), OPT_LOCAL); + set_option_value("list", BOOLEAN_OPTVAL(false), OPT_LOCAL); if (buf->b_ffname != NULL) { buf_set_term_title(buf, buf->b_ffname, strlen(buf->b_ffname)); } -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 676ac954f7..1479656bca 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1444,7 +1444,7 @@ static bool send_mouse_event(Terminal *term, int c) if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { scroll_redraw(direction, curwin->w_botline - curwin->w_topline); } else if (p_mousescroll_vert > 0) { - scroll_redraw(direction, p_mousescroll_vert); + scroll_redraw(direction, (linenr_T)p_mousescroll_vert); } curwin->w_redr_status = true; -- cgit From d0d132fbd055834cbecb3d4e3a123a6ea8f099ec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Jul 2023 21:42:55 +0800 Subject: fix(terminal): don't send unknown special keys to terminal (#24378) Special keys are negative integers, so sending them to terminal leads to strange behavior. --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1479656bca..caa4674cef 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -766,7 +766,7 @@ void terminal_send_key(Terminal *term, int c) if (key) { vterm_keyboard_key(term->vt, key, mod); - } else { + } else if (!IS_SPECIAL(c)) { vterm_keyboard_unichar(term->vt, (uint32_t)c, mod); } } -- cgit From b74262a336d3e5cf69930fcec69a12fdad16d76c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 08:00:42 +0800 Subject: fix(terminal): send Shift-Home Shift-End Ctrl-Home Ctrl-End (#24418) --- src/nvim/terminal.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index caa4674cef..1dacc496b6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1095,6 +1095,8 @@ static void convert_modifiers(int key, VTermModifier *statep) case K_S_DOWN: case K_S_LEFT: case K_S_RIGHT: + case K_S_HOME: + case K_S_END: case K_S_F1: case K_S_F2: case K_S_F3: @@ -1112,6 +1114,8 @@ static void convert_modifiers(int key, VTermModifier *statep) case K_C_LEFT: case K_C_RIGHT: + case K_C_HOME: + case K_C_END: *statep |= VTERM_MOD_CTRL; break; } @@ -1158,8 +1162,16 @@ static VTermKey convert_key(int key, VTermModifier *statep) return VTERM_KEY_INS; case K_DEL: return VTERM_KEY_DEL; + case K_S_HOME: + FALLTHROUGH; + case K_C_HOME: + FALLTHROUGH; case K_HOME: return VTERM_KEY_HOME; + case K_S_END: + FALLTHROUGH; + case K_C_END: + FALLTHROUGH; case K_END: return VTERM_KEY_END; case K_PAGEUP: -- cgit From f2ce31d3dc1c728c33c0910e1a9970f0eb2e3f11 Mon Sep 17 00:00:00 2001 From: fredizzimo Date: Sun, 23 Jul 2023 11:01:51 -0400 Subject: fix(terminal): call validate_cursor() before screen update (#24425) Problem: When the CurSearch highlight group is set, and a search is active and you are listening to the remote UI "win_viewport" events, then typing is very unresponsive, because "win_viewport" is not sent as soon as the character is typed. On the other hand if you refresh the screen on "flush", the screen will scroll with a delay since "win_viewport" comes too late. I estimate this delay be up to one second, but it varies. Solution: Call validate_cursor() before drawing the screen, just like other modes. No tests have been added because only the intermediate state is wrong. --- src/nvim/terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1dacc496b6..56f364bf0a 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -532,6 +532,7 @@ static int terminal_check(VimState *state) } terminal_check_cursor(); + validate_cursor(); if (must_redraw) { update_screen(); -- cgit From 0a7fda6fa0067ee61fee60d123967c3f14431007 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 09:34:13 +0800 Subject: fix(terminal): include modifiers when forwarding mouse (#24549) --- src/nvim/terminal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 56f364bf0a..3315936b6a 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1444,7 +1444,9 @@ static bool send_mouse_event(Terminal *term, int c) return false; } - mouse_action(term, button, row, col - offset, pressed, 0); + VTermModifier mod = VTERM_MOD_NONE; + convert_modifiers(c, &mod); + mouse_action(term, button, row, col - offset, pressed, mod); return false; } -- cgit From 21d466c1b985bcb0b80cd71d3b33eef6c24004f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 10:24:27 +0800 Subject: fix(terminal): forward horizontal mouse scrolling (#24552) --- src/nvim/terminal.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 3315936b6a..a7e810087a 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -577,6 +577,8 @@ static int terminal_execute(VimState *state, int key) case K_RIGHTRELEASE: case K_MOUSEDOWN: case K_MOUSEUP: + case K_MOUSELEFT: + case K_MOUSERIGHT: if (send_mouse_event(s->term, key)) { return 0; } @@ -1440,6 +1442,10 @@ static bool send_mouse_event(Terminal *term, int c) pressed = true; button = 4; break; case K_MOUSEUP: pressed = true; button = 5; break; + case K_MOUSELEFT: + pressed = true; button = 7; break; + case K_MOUSERIGHT: + pressed = true; button = 6; break; default: return false; } -- cgit From d401b33314a4178b23443c78119055c3d34a407e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 23:19:12 +0800 Subject: fix(terminal): handle horizontal scrolling in another window (#24828) --- src/nvim/terminal.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index a7e810087a..2d21451c9d 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -79,6 +79,7 @@ #include "nvim/move.h" #include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/normal.h" +#include "nvim/ops.h" #include "nvim/option.h" #include "nvim/optionstr.h" #include "nvim/pos.h" @@ -1456,18 +1457,38 @@ static bool send_mouse_event(Terminal *term, int c) return false; } - if (c == K_MOUSEDOWN || c == K_MOUSEUP) { + if (c == K_MOUSEUP || c == K_MOUSEDOWN || c == K_MOUSELEFT || c == K_MOUSERIGHT) { win_T *save_curwin = curwin; // switch window/buffer to perform the scroll curwin = mouse_win; curbuf = curwin->w_buffer; - int direction = c == K_MOUSEDOWN ? MSCR_DOWN : MSCR_UP; - if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { - scroll_redraw(direction, curwin->w_botline - curwin->w_topline); - } else if (p_mousescroll_vert > 0) { - scroll_redraw(direction, (linenr_T)p_mousescroll_vert); + + cmdarg_T cap; + oparg_T oa; + CLEAR_FIELD(cap); + clear_oparg(&oa); + cap.oap = &oa; + + switch (cap.cmdchar = c) { + case K_MOUSEUP: + cap.arg = MSCR_UP; + break; + case K_MOUSEDOWN: + cap.arg = MSCR_DOWN; + break; + case K_MOUSELEFT: + cap.arg = MSCR_LEFT; + break; + case K_MOUSERIGHT: + cap.arg = MSCR_RIGHT; + break; + default: + abort(); } + // Call the common mouse scroll function shared with other modes. + do_mousescroll(&cap); + curwin->w_redr_status = true; curwin = save_curwin; curbuf = curwin->w_buffer; -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 2d21451c9d..5e0ff072fb 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1750,7 +1750,7 @@ static void refresh_screen(Terminal *term, buf_T *buf) int change_start = row_to_linenr(term, term->invalid_start); int change_end = change_start + changed; - changed_lines(change_start, 0, change_end, added, true); + changed_lines(buf, change_start, 0, change_end, added, true); term->invalid_start = INT_MAX; term->invalid_end = -1; } -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/terminal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 5e0ff072fb..0f27445a53 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -438,8 +438,8 @@ bool terminal_enter(void) char *save_w_p_culopt = NULL; uint8_t save_w_p_culopt_flags = curwin->w_p_culopt_flags; int save_w_p_cuc = curwin->w_p_cuc; - long save_w_p_so = curwin->w_p_so; - long save_w_p_siso = curwin->w_p_siso; + OptInt save_w_p_so = curwin->w_p_so; + OptInt save_w_p_siso = curwin->w_p_siso; if (curwin->w_p_cul && curwin->w_p_culopt_flags & CULOPT_NBR) { if (strcmp(curwin->w_p_culopt, "number") != 0) { save_w_p_culopt = curwin->w_p_culopt; -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/terminal.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 0f27445a53..de8eee0cab 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -59,8 +59,6 @@ #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" -#include "nvim/event/loop.h" #include "nvim/event/multiqueue.h" #include "nvim/event/time.h" #include "nvim/ex_docmd.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index de8eee0cab..169525da20 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -79,6 +79,7 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/optionstr.h" #include "nvim/pos.h" #include "nvim/state.h" -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/terminal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 169525da20..5d1bd09a6c 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -714,7 +714,7 @@ static bool is_filter_char(int c) return !!(tpf_flags & flag); } -void terminal_paste(long count, char **y_array, size_t y_size) +void terminal_paste(int count, char **y_array, size_t y_size) { if (y_size == 0) { return; @@ -1584,7 +1584,7 @@ static void refresh_terminal(Terminal *term) } return; } - long ml_before = buf->b_ml.ml_line_count; + linenr_T ml_before = buf->b_ml.ml_line_count; // refresh_ functions assume the terminal buffer is current aco_save_T aco; @@ -1594,7 +1594,7 @@ static void refresh_terminal(Terminal *term) refresh_screen(term, buf); aucmd_restbuf(&aco); - long ml_added = buf->b_ml.ml_line_count - ml_before; + int ml_added = buf->b_ml.ml_line_count - ml_before; adjust_topline(term, buf, ml_added); } @@ -1754,7 +1754,7 @@ static void refresh_screen(Terminal *term, buf_T *buf) term->invalid_end = -1; } -static void adjust_topline(Terminal *term, buf_T *buf, long added) +static void adjust_topline(Terminal *term, buf_T *buf, int added) { FOR_ALL_TAB_WINDOWS(tp, wp) { if (wp->w_buffer == buf) { -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/terminal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 5d1bd09a6c..b50ab4ddb0 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -160,13 +160,13 @@ struct terminal { }; static VTermScreenCallbacks vterm_screen_callbacks = { - .damage = term_damage, - .moverect = term_moverect, - .movecursor = term_movecursor, + .damage = term_damage, + .moverect = term_moverect, + .movecursor = term_movecursor, .settermprop = term_settermprop, - .bell = term_bell, + .bell = term_bell, .sb_pushline = term_sb_push, // Called before a line goes offscreen. - .sb_popline = term_sb_pop, + .sb_popline = term_sb_pop, }; static Set(ptr_t) invalidated_terminals = SET_INIT; -- cgit From 684e93054b82c6b5b215db7d3ecbad803eb81f0e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 25 Oct 2023 09:59:02 +0800 Subject: fix(terminal): assign channel to terminal earlier (#25771) --- src/nvim/terminal.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index b50ab4ddb0..a564738243 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -203,10 +203,11 @@ static void term_output_callback(const char *s, size_t len, void *user_data) /// /// @param buf Buffer used for presentation of the terminal. /// @param opts PTY process channel, various terminal properties and callbacks. -Terminal *terminal_open(buf_T *buf, TerminalOptions opts) +void terminal_open(Terminal **termpp, buf_T *buf, TerminalOptions opts) + FUNC_ATTR_NONNULL_ALL { // Create a new terminal instance and configure it - Terminal *rv = xcalloc(1, sizeof(Terminal)); + Terminal *rv = *termpp = xcalloc(1, sizeof(Terminal)); rv->opts = opts; rv->cursor.visible = true; // Associate the terminal instance with the new buffer @@ -251,18 +252,26 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) RESET_BINDING(curwin); // Reset cursor in current window. curwin->w_cursor = (pos_T){ .lnum = 1, .col = 0, .coladd = 0 }; - // Initialize to check if the scrollback buffer has been allocated inside a TermOpen autocmd + // Initialize to check if the scrollback buffer has been allocated in a TermOpen autocmd. rv->sb_buffer = NULL; // Apply TermOpen autocmds _before_ configuring the scrollback buffer. apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, buf); - // Local 'scrollback' _after_ autocmds. - buf->b_p_scbk = (buf->b_p_scbk < 1) ? SB_MAX : buf->b_p_scbk; aucmd_restbuf(&aco); - // Configure the scrollback buffer. - rv->sb_size = (size_t)buf->b_p_scbk; - rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size); + if (*termpp == NULL) { + return; // Terminal has already been destroyed. + } + + if (rv->sb_buffer == NULL) { + // Local 'scrollback' _after_ autocmds. + if (buf->b_p_scbk < 1) { + buf->b_p_scbk = SB_MAX; + } + // Configure the scrollback buffer. + rv->sb_size = (size_t)buf->b_p_scbk; + rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size); + } // Configure the color palette. Try to get the color from: // @@ -290,14 +299,13 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) } } } - - return rv; } /// Closes the Terminal buffer. /// /// May call terminal_destroy, which sets caller storage to NULL. void terminal_close(Terminal **termpp, int status) + FUNC_ATTR_NONNULL_ALL { Terminal *term = *termpp; if (term->destroy) { @@ -647,6 +655,7 @@ static int terminal_execute(VimState *state, int key) /// Frees the given Terminal structure and sets the caller storage to NULL (in the spirit of /// XFREE_CLEAR). void terminal_destroy(Terminal **termpp) + FUNC_ATTR_NONNULL_ALL { Terminal *term = *termpp; buf_T *buf = handle_get_buffer(term->buf_handle); -- cgit From c881092ffe9d6760d08efcd4dfb02efcb60cc706 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Oct 2023 12:05:37 +0800 Subject: fix(terminal): don't lose focus on (#25845) --- src/nvim/terminal.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index a564738243..fbfe8c04a6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1506,13 +1506,14 @@ static bool send_mouse_event(Terminal *term, int c) return mouse_win == curwin; } - // ignore left release action if it was not processed above - // to prevent leaving Terminal mode after entering to it using a mouse - if (c == K_LEFTRELEASE && mouse_win->w_buffer->terminal == term) { +end: + // Ignore left release action if it was not forwarded to prevent + // leaving Terminal mode after entering to it using a mouse. + if ((c == K_LEFTRELEASE && mouse_win != NULL && mouse_win->w_buffer->terminal == term) + || c == K_MOUSEMOVE) { return false; } -end: ins_char_typebuf(vgetc_char, vgetc_mod_mask); return true; } -- cgit From d4c2fc6ff6c579b2588f0e3ba02e5cbe58308c6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Oct 2023 15:23:20 +0800 Subject: fix(terminal): keep focus when scrolling number column of another window (#25848) --- src/nvim/terminal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index fbfe8c04a6..a4ae8d2ae2 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1417,13 +1417,14 @@ static void mouse_action(Terminal *term, int button, int row, int col, bool pres static bool send_mouse_event(Terminal *term, int c) { int row = mouse_row, col = mouse_col, grid = mouse_grid; - int offset; win_T *mouse_win = mouse_find_win(&grid, &row, &col); - if (mouse_win == NULL || (offset = win_col_off(mouse_win)) > col) { + if (mouse_win == NULL) { goto end; } - if (term->forward_mouse && mouse_win->w_buffer->terminal == term) { + int offset; + if (term->forward_mouse && mouse_win->w_buffer->terminal == term + && col >= (offset = win_col_off(mouse_win))) { // event in the terminal window and mouse events was enabled by the // program. translate and forward the event int button; -- cgit From 3294d654166ec26cac58037a0358b9f7ea75b2d6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:48:45 +0100 Subject: PVS fixes * build(PVS): exclude mpack and klib as they are external dependencies * build(PVS): suppress warning V601 See https://pvs-studio.com/en/docs/warnings/v601/ * fix(PVS/V009): add top-level message * fix(PVS/V547): expression 'p != NULL' is always true * fix(PVS/V547): expression '* termpp == NULL' is always false --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index a4ae8d2ae2..465d1d0cbc 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -259,7 +259,7 @@ void terminal_open(Terminal **termpp, buf_T *buf, TerminalOptions opts) aucmd_restbuf(&aco); - if (*termpp == NULL) { + if (*termpp == NULL) { // -V547 return; // Terminal has already been destroyed. } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/terminal.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 465d1d0cbc..ca9777f1d6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // VT220/xterm-like terminal emulator. // Powered by libvterm http://www.leonerd.org.uk/code/libvterm // @@ -236,7 +233,7 @@ void terminal_open(Terminal **termpp, buf_T *buf, TerminalOptions opts) aucmd_prepbuf(&aco, buf); refresh_screen(rv, buf); - set_option_value("buftype", STATIC_CSTR_AS_OPTVAL("terminal"), OPT_LOCAL); // -V666 + set_option_value("buftype", STATIC_CSTR_AS_OPTVAL("terminal"), OPT_LOCAL); // Default settings for terminal buffers buf->b_p_ma = false; // 'nomodifiable' @@ -259,7 +256,7 @@ void terminal_open(Terminal **termpp, buf_T *buf, TerminalOptions opts) aucmd_restbuf(&aco); - if (*termpp == NULL) { // -V547 + if (*termpp == NULL) { return; // Terminal has already been destroyed. } @@ -731,7 +728,7 @@ void terminal_paste(int count, char **y_array, size_t y_size) vterm_keyboard_start_paste(curbuf->terminal->vt); size_t buff_len = strlen(y_array[0]); char *buff = xmalloc(buff_len); - for (int i = 0; i < count; i++) { // -V756 + for (int i = 0; i < count; i++) { // feed the lines to the terminal for (size_t j = 0; j < y_size; j++) { if (j) { -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/terminal.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index ca9777f1d6..025efce7c8 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -59,6 +59,7 @@ #include "nvim/event/multiqueue.h" #include "nvim/event/time.h" #include "nvim/ex_docmd.h" +#include "nvim/func_attr.h" #include "nvim/getchar.h" #include "nvim/globals.h" #include "nvim/highlight.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 025efce7c8..28f532d986 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -79,7 +79,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/optionstr.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/state.h" #include "nvim/terminal.h" #include "nvim/types.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 28f532d986..4cbba9a14f 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -82,7 +82,7 @@ #include "nvim/pos_defs.h" #include "nvim/state.h" #include "nvim/terminal.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/terminal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/terminal.c') diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 4cbba9a14f..1527738165 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -45,7 +45,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" @@ -65,9 +65,9 @@ #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -84,7 +84,7 @@ #include "nvim/terminal.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" typedef struct terminal_state { VimState state; -- cgit