Problem: `tui->space_buf` may be smaller than the width of the TUI or widest
grid, causing an overflow when calling `tui_grid_clear` if `print_spaces` is
called from `clear_region` (clears the TUI's screen since #23428).
Solution: resize `space_buf` to be wide enough to fit the TUI or widest grid.
Didn't bother shrinking the allocation if the max widths decrease.
Problems:
1. The test case for querying truecolor support did not check which
capabilities were queried
2. The test case for querying truecolor support checked `&termguicolors`
in the Nvim test runner, not the child Nvim in the the embedded
terminal
3. The test case for querying truecolor support did not actually respond
to the XTGETTCAP requests. `'termguicolors'` is still enabled even
without responding to this query because libvterm understands and
responds to the DECRQSS request, but it is still good to respond to
the query explicitly instead of depending on hidden libvterm behavior
4. No test case exists at all for OSC 52
Solution:
Fix all of the problems listed above.
Extmarks can contain URLs which can then be drawn in any supporting UI.
In the TUI, for example, URLs are "drawn" by emitting the OSC 8 control
sequence to the TTY. On terminals which support the OSC 8 sequence this
will create clickable hyperlinks.
URLs are treated as inline highlights in the decoration subsystem, so
are included in the `DecorSignHighlight` structure. However, unlike
other inline highlights they use allocated memory which must be freed,
so they set the `ext` flag in `DecorInline` so that their lifetimes are
managed along with other allocated memory like virtual text.
The decoration subsystem then adds the URLs as a new highlight
attribute. The highlight subsystem maintains a set of unique URLs to
avoid duplicating allocations for the same string. To attach a URL to an
existing highlight attribute we call `hl_add_url` which finds the URL in
the set (allocating and adding it if it does not exist) and sets the
`url` highlight attribute to the index of the URL in the set (using an
index helps keep the size of the `HlAttrs` struct small).
This has the potential to lead to an increase in highlight attributes
if a URL is used over a range that contains many different highlight
attributes, because now each existing attribute must be combined with
the URL. In practice, however, URLs typically span a range containing a
single highlight (e.g. link text in Markdown), so this is likely just a
pathological edge case.
When a new highlight attribute is defined with a URL it is copied to all
attached UIs with the `hl_attr_define` UI event. The TUI manages its own
set of URLs (just like the highlight subsystem) to minimize allocations.
The TUI keeps track of which URL is "active" for the cell it is
printing. If no URL is active and a cell containing a URL is printed,
the opening OSC 8 sequence is emitted and that URL becomes the actively
tracked URL. If the cursor is moved while in the middle of a URL span,
we emit the terminating OSC sequence to prevent the hyperlink from
spanning multiple lines.
This does not support nested hyperlinks, but that is a rare (and,
frankly, bizarre) use case. If a valid use case for nested hyperlinks
ever presents itself we can address that issue then.
The motivation for this update is Issue #15365, where background=light
is not properly set for Nvim running from an Nvim :terminal. This can be
encountered when e.g., opening a terminal to make git commits, which
opens EDITOR=nvim in the nested terminal.
Under the implementation of this commit, the OSC response always
indicates a black or white foreground/background. While this may not
reflect the actual foreground/background color, it permits 'background'
to be retained for a nested Nvim instance running in the terminal
emulator. The behaviour matches Vim.
This commit implements a new TermRequest autocommand event and has Neovim
emit this event when children of terminal buffers emit an OSC or DCS sequence
libvterm does not handle.
The TermRequest autocommand event has additional data in the
v:termrequest variable.
Co-authored-by: Gregory Anders <greg@gpanders.com>
Since execl() is a variadic function, it requries a NULL-terminal to
indicate the end of its argument list, c.f. exec(3)
> The first argument, by convention, should point to the filename
> associated with the file being executed. The list of arguments *must*
> be terminated by a null pointer
This fixes the failure seen on aarch64 and i386, due to garbage data
being considered part of the variadic arguments.
Problem: Updating default color scheme produced some feedback.
Solution: Address the feedback.
Outline of the changes:
- Colors `Grey1` and `Grey2` are made a little bit more extreme (dark -
darker, light - lighter) to increase overall contrast.
- `gui` colors are treated as base with `cterm` colors falling back to
using 0-15 colors which come from terminal emulator.
- Update highlight group definition to not include attribute definition
if it is intended to staty uncolored.
- Tweak some specific highlight groups.
- Add a list of Neovim specific highlight groups which are now defined
differently in a breaking way.
- Minor tweaks in several other places related to default color scheme.
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.
This is the command invoked repeatedly to make the changes:
:%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
Rather than writing the synchronized update begin and end sequences into
the TUI's internal buffer (where it is later flushed to the TTY), write
these sequences directly to the TTY before and after the TUI's internal
buffer is itself flushed to the TTY.
This guarantees that a synchronized update is always used when we are
actually sending data to the TTY. This means we do not need to keep
track of the TUI's "dirty" state (any sequences which affect the TUI
state will be written in the TUI's internal buffer, which is now
guaranteed to only ever be written when a synchronized update is
active).
Currently, the value of $COLORTERM in :terminal in tests depends on
outer environment because of 'notermguicolors'.
If $COLORTERM is not set in :terminal, an inner Nvim instance will try
to detect 'termguicolors' support, which may interfere with tests.
So set 'termguicolors' in outer Nvim instance unless $COLORTERM needs to
be overridden, and unset it in inner Nvim instance when running TUI.
Set 'notermguicolors' in tests which spawn a child Nvim process to force
existing tests to use 16 colors. Also refactor the child process
invocation to make things a little bit less messy.
Problem: Default color scheme is suboptimal.
Solution: Start using new color scheme. Introduce new `vim` color scheme
for opt-in backward compatibility.
------
Main design ideas
- Be "Neovim branded".
- Be minimal for 256 colors with a bit more shades for true colors.
- Be accessible through high enough contrast ratios.
- Be suitable for dark and light backgrounds via exchange of dark and
light palettes.
------
Palettes
- Have dark and light variants. Implemented through exporeted
`NvimDark*` and `NvimLight*` hex colors.
- Palettes have 4 shades of grey for UI elements and 6 colors (red,
yellow, green, cyan, blue, magenta).
- Actual values are computed procedurally in Oklch color space based on
a handful of hyperparameters.
- Each color has a 256 colors variant with perceptually closest color.
------
Highlight groups
Use:
- Grey shades for general UI according to their design.
- Bold text for keywords (`Statement` highlight group). This is an
important choice to increase accessibility for people with color
deficiencies, as it doesn't rely on actual color.
- Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some
minor text UI elements.
- Cyan as main syntax color, i.e. for function usage (`Function`
highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI
elements.
- Red to generally mean high user attention, i.e. errors; in particular
for `ErrorMsg`, `DiffDelete`, `DiagnosticError`.
- Yellow very sparingly only with true colors to mean mild user
attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`.
- Blue very sparingly only with true colors as `DiagnosticHint` and some
additional important syntax group (like `Identifier`).
- Magenta very carefully (if at all).
------
Notes
- To make tests work without relatively larege updates, each one is
prepended with an equivalent of the call `:colorscheme vim`.
Plus some tests which spawn new Neovim instances also now use 'vim'
color scheme.
In some cases tests are updated to fit new default color scheme.
Some escape sequences (in particular, OSC 52 paste responses) can be
very large, even unbounded in length. These can easily overflow
termkey's internal buffer. In order to process these long sequences,
dynamically grow termkey's internal buffer.
libtermkey does not interpret OSC sequences that end with a BEL (0x07)
instead of an ST (0x1b 0x5c) terminator. This causes these tests to fail
since the OSC response is now parsed via libtermkey. Change the tests to
use the ST terminator to appease libtermkey.
The 'arabicshape' feature of vim is a transformation of unicode text to
make arabic and some related scripts look better at display time. In
particular the content of a cell will be adjusted depending on the
(original) content of the cells just before and after it.
This is implemented by the arabic_shape() function in nvim. Before this
commit, shaping was invoked in four different contexts:
- when rendering buffer text in win_line()
- in line_putchar() for rendering virtual text
- as part of grid_line_puts, used by messages and statuslines and
similar
- as part of draw_cmdline() for drawing the cmdline
This replaces all these with a post-processing step in grid_put_linebuf(),
which has become the entry point for all text rendering after recent
refactors.
An aim of this is to make the handling of multibyte text yet simpler.
One of the main reasons multibyte chars needs to be "parsed" into
codepoint arrays of composing chars is so that these could be inspected
for the purpose of shaping. This can likely be vastly simplified in many
contexts where only the total length (in bytes) and width of composed
char is needed.
The terminal buffer closes automatically when using `:terminal` and the
command exits without an error. This messes up some tests that expect
the terminal buffer to still be open. We can force the buffer not to
close by passing an argument to `:terminal`. This can be anything, since
the shell-test stub simply prints whatever argument it's given.
Avoid consecutive RPC requests involving :startinsert or :stopinsert,
because consecutive RPC requests may be processed together, before the
:startinsert or :stopinsert takes effect.
Also change some feed_command() to command() to make tests faster.
Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer
text, which is forbidden during textlock. Additionally, nvim_open_term() and
termopen() may be used to convert the cmdwin buffer into a terminal buffer,
which is weird.
Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but
disallow nvim_open_term() from converting the cmdwin buffer into a terminal
buffer. termopen() is not allowed in the cmdwin (as it always operates on
curbuf), so just check text_locked().
Also happens to improve the error in #21055: nvim_buf_set_text() was callable
during textlock, but happened to check textlock indirectly via u_save();
however, this caused the error to be overwritten by an unhelpful "Failed to
save undo information" message when msg_list == NULL (e.g: an `<expr>` mapping
invoked outside of do_cmdline()).
Problem: Message is cleared when removing mode message (Gary Johnson).
Solution: Do not clear the command line after displaying a message.
800cdbb7ca
Co-authored-by: Bram Moolenaar <Bram@vim.org>
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.
`nvim_(get|set)_option_value` pick the current buffer / window by default for buffer-local/window-local (but not global-local) options. So specifying `buf = 0` or `win = 0` in opts is unnecessary for those options. This PR removes those to reduce code clutter.
Problem: When setting a shell size smaller than the containing
terminal window through `:winsize` or `:set lines/columns`
the screen is not properly cleared.
Solution: Clear the tui dimensions rather than the grid dimensions.
Problem:
Codebase inconsistently binds vim.api onto a or api.
Solution:
Use api everywhere. a as an identifier is too short to have at the
module level.
Problem:
"tmux 3.2a" (output from "tmux -V") is not parsed easily.
Solution:
With `strict=false`, discard everything before the first digit.
- rename Semver => Version
- rename vim.version.version() => vim.version._version()
- rename matches() => has()
- remove `opts` from cmp()
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
Problem:
has('gui_running') is still common in the wild and our answer has
changed over time, causing frustration.
95a6ccbe9f
Solution:
Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI.
Included patches:
821. By Paul "LeoNerd" Evans on 2022-12-29
Don't bother to emit the unrecognised sequence in DECRQSS response as it provides an echo roundtrip possibility
820. By Paul "LeoNerd" Evans on 2022-11-26
erase_internal() should only set fg/bg colour, resetting other attributes (especially RV)
819. By Paul "LeoNerd" Evans on 2022-11-09
Added vterm_screen_set_default_colors(), which repaints the cells in the buffer(s)
818. By Paul "LeoNerd" Evans on 2022-11-09
Permit either colour argument to be NULL to vterm_state_set_default_colors()
817. By Paul "LeoNerd" Evans on 2022-10-01
Delete the mk_wcswidth functions as they're not used; guard the CJK-wide one with an ifdef as by default we don't use it
816. By Paul "LeoNerd" Evans on 2022-10-01
Make sure to supply empty (void) prototype to functions that take no arguments in bin/vterm-ctrl.c