Repository navigation
Light-background flash on startup in dark terminals - #21664
akasakariko wants to merge 1 commit into
Conversation
|
So it would 100ms to vim startup for terminals that fail to respond for And if the response comes late, does it mean the flicker light->dark would still happen in case |
|
Yes to both, with some conditions During interactive startup, if A response arriving after the timeout can still cause a light-to-dark flash |
|
CI retry update The empty commit a54bf7e retriggers CI with an identical source tree and no changes to tests or coverage thresholds The original project coverage drop is concentrated in incorrectly attributed In the retry, Could a maintainer rerun the Linux huge Clang job? |
b7912af to
e42c079
Compare
This would generate quite a few issues here.
We already had that. The patch was reverted in the end due to multiple issues raised, as far as I remember. |
|
Pushed e42c079
Verified locally with GCC and Clang coverage reproductions, the actual Codecov gcov plugin, the startup and terminal position regressions, all clipboard and Wayland tests, and libvterm tests The Linux non-GUI startup suite passed with its existing GUI skips In CI run 40798043666, both Linux GCC and Clang full-test jobs passed, including the previously failing clipboard test Two new failures remain in unchanged test files
Could a maintainer rerun these two jobs |
|
I will handle it. |
|
@habamax Thanks for the feedback I reproduced the 100 ms wait with an unresponsive terminal and a light-to-dark flash when the background response arrived after the timeout Before revising this PR, which direction would you prefer?
If neither approach is appropriate, what alternative would you recommend? |
There definitely shouldn't be an added wait by default, not 100ms at least given that my (and many others) full vim config is loaded under 50ms and bare vim is way less.
I would go with opt-in configurable wait, but that is for @chrisbra @64-bitman and the team to decide.
I can't find it, I just remember there was an email thread in vim.dev about vim unexpectedly changing colors after some time (due to late terminal response to t_RB or something). |
|
Thanks, I will wait for the direction from the team |
|
I think we should make the startup wait an option (default no), and update documentation to point users experiencing this problem to that option. |
|
Thanks, I will submit the update this afternoon (Tokyo time) |
|
I have addressed the feedback |
7277aaf to
1e18739
Compare
1e18739 to
7d40247
Compare
|
Pushed 61f336c to address the review comments and the shared CI failure
Local validation on macOS arm64
Local limitations are not counted as passes
GitHub verification for 61f336c is now complete
|
jparise
left a comment
There was a problem hiding this comment.
Thanks for working on this! I gave it a try and found a few issues (regressions) related to child commands to consider:
- With the default
termbackgroundwait=0, automatic background, and-c 'qall!', an OSC 11 reply sent 20ms after the query ends up being echoed after Vim exits. - With
termbackgroundwait=50and a startup:!command running a raw-terminal reader, Ctrl-C at 70ms followed by the background reply at 110ms lets the child read the literal OSC 11 response as input. The child receives no response bytes on the base revision. - With
termbackgroundwait=50, set t_ti= t_te=, and a startup:!command, a dark reply at 80ms triggers a redraw after the final color reset. The child inherits Vim’s gray-on-black colors.
Problem: The startup background handoff test can send CTRL-C before
startup commands run on a slow machine.
Solution: Start the input timers after an explicit handoff marker and
exercise slow initialization in the existing test (akasakariko).
related: vim#21664
Assisted-by: Codex
Signed-off-by: akasakariko <[email protected]>
99be34e to
6056bb5
Compare
6aabc6b to
9cca569
Compare
Problem: The Windows SGR regression test can select WinPTY, which
drops underline attributes, or launch a GUI in DLL builds.
Solution: Use the console sibling executable with ConPTY, retaining
the existing text, underline and exit assertions (akasakariko).
Report unavailable ConPTY as a feature skip on older Windows versions.
related: vim#21664
Signed-off-by: akasakariko <[email protected]>
Problem: Slow Azure mirror downloads and inconsistent cached debug
indexes can abort CI before Vim is compiled or tested.
Solution: Select the primary Ubuntu archive over HTTPS in source and
mirror lists, bound waits for downloads, and retry full index
refreshes after clearing stale debug metadata (akasakariko).
Return the final APT error if all retries fail.
related: vim#21664
Signed-off-by: akasakariko <[email protected]>
92ee40e to
c55cd7f
Compare
This is the revert 27822a0 |
|
Thanks @jparise, all three issues raised in your review have been addressed in 4ca831d |
|
With the default 'termbackgroundwait' (0), this PR sends the OSC 11 I used the script below (Python 3, tried on Linux). It runs Vim takes 100 ms longer to quit, also when the reply comes after With DELAY 150 the reply comes after Vim quits. It is shown in the osc11_term.py#!/usr/bin/env python3
# Fake terminal that answers the OSC 11 query after DELAY ms.
# Usage: python3 osc11_term.py VIM DELAY_MS (DELAY_MS < 0: no reply)
# Runs "VIM --clean -c qa" on a pty, then shows how long Vim took and
# what the shell got after Vim exited.
import os, pty, select, struct, sys, termios, fcntl, time
vim, delay = sys.argv[1], int(sys.argv[2])
after = ("import os,sys,termios,time; time.sleep(0.5); fd=0; "
"a=termios.tcgetattr(fd); b=termios.tcgetattr(fd); "
"b[3]&=~(termios.ICANON|termios.ECHO); b[6][termios.VMIN]=0; "
"b[6][termios.VTIME]=0; termios.tcsetattr(fd,termios.TCSANOW,b); "
"d=os.read(fd,4096); termios.tcsetattr(fd,termios.TCSANOW,a); "
"print('unread input:', repr(d))")
pid, fd = pty.fork()
if pid == 0:
os.environ['TERM'] = 'xterm-256color'
os.execvp('sh', ['sh', '-c', '"$0" --clean -c qa; printf "@EXIT@"; '
'python3 -c "$1"', vim, after])
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack('HHHH', 24, 80, 0, 0))
start = time.monotonic()
out, reply_at, replied, exited = b'', None, False, None
while time.monotonic() < start + 3:
if select.select([fd], [], [], 0.005)[0]:
try:
data = os.read(fd, 4096)
except OSError:
break
if not data:
break
out += data
now = time.monotonic()
if reply_at is None and delay >= 0 and b'\x1b]11;?' in out:
reply_at = now + delay / 1000
if reply_at and not replied and now >= reply_at:
os.write(fd, b'\x1b]11;rgb:0000/0000/0000\x1b\\')
replied = True
if exited is None and b'@EXIT@' in out:
exited = now
print('OSC 11 query sent:', b'\x1b]11;?' in out)
print('Vim took: %d ms' % ((exited - start) * 1000))
rest = out.split(b'@EXIT@', 1)[1]
shown, _, unread = rest.partition(b'unread input:')
print('shown in the shell:', shown.decode(errors='replace').strip())
print('unread input:', unread.decode(errors='replace').strip())Also, about four commits only change the CI results, and I don't know |
Problem: An early OSC 11 query with termbackgroundwait=0 adds an exit
delay and can leave a late response in the caller's input.
Solution: Query before startup commands only when the wait is positive,
document the default query timing, and cover both default and
opt-in exits (akasakariko).
Restore the unrelated CI configuration and terminal tests to the base
revision, retaining the startup background test's true-color setup.
related: vim#21664
Signed-off-by: akasakariko <[email protected]>
|
Thanks @h-east, fixed in 497f025 With the default termbackgroundwait=0, the background query is now deferred until after startup commands, so I reproduced the exit delay and late-response leak with your script before the fix I also removed the unrelated CI, APT, Filelist, and terminal3 changes from the PR diff Local build and the startup, termcodes, options, messages, and autocmd suites passed with platform and feature skips |
|
CI follow-up for 497f025 All checks have finished, with 33 reported as successful and 7 failed Five test jobs fail in Test_crash1_2 at the same crash 6 / Xdiff step: Linux HUGE GCC, Linux HUGE Clang, Linux ASan newtests 2, and both macOS HUGE builds I built upstream 88d96a1 locally and measured about 4.4 seconds for the failing test, compared with about 0.5 seconds on this branch Both Codecov checks remain red with incomplete uploads, including skipped uploads from the failed HUGE jobs The upstream rerun API returns HTTP 403 for this account |
Problem: Current upstream makes Test_crash1_2 time out in several CI
configurations, preventing complete coverage uploads.
Solution: Integrate the diff fold performance fix from PR vim#21782,
preserving its original commit and author (akasakariko).
related: vim#21664
related: vim#21782
Signed-off-by: akasakariko <[email protected]>
|
Follow-up in b1a91cd Integrated the original #21782 commit 8f37741 to address the upstream diff fold slowdown that caused five Test_crash1_2 failures The complete diffmode, fold, crash, startup, termcodes, options, messages, and autocmd suites pass locally, with 616 tests executed and the existing platform and feature skips A fresh full CI run is starting on this head, including the coverage uploads missing from the previous failed jobs |
|
CI result for b1a91cd: all 40 GitHub checks report success, with no pending checks The five previous Test_crash1_2 failures are resolved, and both coverage checks pass after the full terminal and GUI coverage uploads One qualification from the job logs: GTK4 still timed out in Test_cscopeWithCscopeConnections under the repository's existing continue-on-error policy |
jparise
left a comment
There was a problem hiding this comment.
In my local experiment, I also had this idea for both color response redraws:
if (starting == 0)
redraw_asap(UPD_CLEAR);
else
redraw_later(UPD_CLEAR);The thinking is that we only need to update the colors but don't need to (re)draw until startup has finished preparing the buffer. I'm not sure this improves the output presentation in practice though.
Problem: Color responses request an immediate redraw while startup is
still preparing buffers.
Solution: Defer both the automatic background response redraw and the
OSC autocmd redraw until startup has finished, retaining
immediate redraws afterwards (Asuka).
related: vim#21664
Signed-off-by: Asuka <[email protected]>
Problem: This branch's comparison still includes the diff fold performance
fix now integrated in upstream master.
Solution: Merge current master to remove the redundant dependency from
the PR diff while retaining its original history (Asuka).
related: vim#21664
related: vim#21782
Signed-off-by: Asuka <[email protected]>
|
Thanks @jparise, applied to both redraw call sites in 9f3389a The background value is still updated immediately, with I compared PTY captures for both automatic background detection and an OSC autocmd changing background The Huge and Tiny builds and the complete startup, termcodes, messages, autocmd, options, and terminal suites pass locally with the existing skips I also merged current master, so the fix from #21782 is now supplied by upstream and its diff no longer appears in this PR |
chrisbra
left a comment
There was a problem hiding this comment.
Can you please squash into a single commit? There are a few commits that are unrelated to the PR, so I'd like to see the final version. Also I noticed the below:
| // Do not read redirected input before executing startup commands. | ||
| if (stdout_isatty && mch_input_isatty()) | ||
| may_req_bg_color(); | ||
| # endif |
There was a problem hiding this comment.
The comment is wrong, the code does not check 'termbackgroundwait'. Also, I think you need to exclude that the gui is running, similar to what is happening in the if branch above.
There was a problem hiding this comment.
Addressed in 3a39bd1
The call site now explicitly checks p_tbw > 0, terminal input and output, and !gui.in_use && !gui.starting
The existing default, zero-wait, positive-wait, and redirected-input startup tests pass
| // Handle pending terminal responses before restoring cooked mode, | ||
| // otherwise they may be echoed as typed text. | ||
| stoptermcap(); | ||
| settmode(TMODE_COOK); |
There was a problem hiding this comment.
switching to cooked mode a bit later here, isn't this causing issues with exit_scroll(), because that one expects that the terminal is already in cooked mode?
There was a problem hiding this comment.
I checked this with PTY captures and could not reproduce a missing carriage return
The screen-output path calls out_char('\n'), which emits CR-LF even in raw mode
Alternate-screen, non-swapping t_ti, empty t_ti, Ex mode, help, and version output all preserve CR-LF locally
In 3a39bd1, the existing handoff test now prints an exit message with a nonempty, non-swapping t_ti and asserts CR-LF before the t_te marker, while retaining its late-response leakage check
I also added an explanatory comment at the call site
Temporarily moving settmode(TMODE_COOK) back before exit_scroll() makes the handoff test fail by echoing the late OSC 11 response
I therefore kept the raw-mode handoff ordering rather than restoring the earlier cooked-mode transition
Problem: Vim may draw a light background in a dark terminal before receiving
the terminal background color response.
Solution: Add the opt-in 'termbackgroundwait' option to query and wait before
the first screen clear, while keeping startup non-blocking by
default (akasakariko).
Measure the wait using elapsed time where supported and stop for a response,
pending input or an interrupt. Only query early with a positive wait value,
terminal input and output, and no GUI. Defer redraws until startup finishes.
Consume OSC notifications without losing typed input or suppressing SafeState.
Keep raw mode until pending responses have been handled during terminal
handoff, and restore terminal colors before running child commands. Verify
that exit_scroll() still emits CR-LF before stoptermcap() in raw mode.
Document the option, its default of zero and the late-response limitation,
and cover startup colors, waiting, input preservation and terminal handoff.
fixes: vim#21605
closes: vim#21664
Signed-off-by: akasakariko <[email protected]>
41bfb87 to
3a39bd1
Compare
|
Squashed the PR into one commit, 3a39bd1, as requested
Local Huge and Tiny builds, Tiny-compatible tests, eight relevant suites, codestyle, preprocessor indentation, and whitespace checks pass CI for the new commit is pending |
Problem: Vim may draw a light background in a dark terminal before receiving
the terminal background color response.
Solution: Add the opt-in 'termbackgroundwait' option to query and wait before
the first screen clear, while keeping startup non-blocking by
default (akasakariko).
Measure the wait using elapsed time where supported and stop for a response,
pending input or an interrupt. Only query early with a positive wait value,
terminal input and output, and no GUI. Defer redraws until startup finishes.
Consume OSC notifications without losing typed input or suppressing SafeState.
Keep raw mode until pending responses have been handled during terminal
handoff, and restore terminal colors before running child commands. Verify
that exit_scroll() still emits CR-LF before stoptermcap() in raw mode.
Document the option, its default of zero and the late-response limitation,
and cover startup colors, waiting, input preservation and terminal handoff.
fixes: vim#21605
closes: vim#21664
Signed-off-by: akasakariko <[email protected]>
3a39bd1 to
48cf56f
Compare
|
thanks |
|
Since 9.2.1375, when 'termbackgroundwait' is set to a positive value,
Before 9.2.1375 the request was sent after the "-c" commands, as the A response that takes longer than 'termbackgroundwait' plus 100 msec Steps to reproduceA real terminal answers too quickly, so this script runs a command in import os, pty, re, select, sys, time
pid, fd = pty.fork()
if pid == 0:
os.environ['TERM'] = 'xterm'
os.execvp('sh', ['sh', '-c', sys.argv[1]])
out, answer_at, start = b'', None, time.monotonic()
while time.monotonic() - start < 5:
if answer_at and time.monotonic() >= answer_at:
os.write(fd, b'\x1b]11;rgb:0000/0000/0000\x1b\\')
answer_at = 0
if select.select([fd], [], [], 0.01)[0]:
try:
data = os.read(fd, 4096)
except OSError:
break
if not data:
break
out += data
if answer_at is None and re.search(rb'\x1b\]11;\?', out):
answer_at = time.monotonic() + 0.4
print('echoed' if b'^[]11;rgb' in out else 'not echoed')Save it as repro.py and run: python3 repro.py "vim -u NONE -N --cmd 'set tbw=50' -c q; sleep 1"
python3 repro.py "vim -u NONE -N --cmd 'set tbw=50' -c '!sleep 1'"Result9.2.1375 prints "echoed" for both commands. The terminal output 9.2.1374 (with "silent! set tbw=50") prints "not echoed" for both. |
|
Thanks @h-east. I reproduced both cases on Vim 9.2.1382 with your script, I've opened #21985 to defer the background query when With the fix, both of your commands print |
Dark terminals can briefly show a light background before Vim receives the terminal background color response
Add 'termbackgroundwait' ('tbw'), defaulting to 0, so users can opt into waiting before the first screen clear
The default keeps terminal queries after startup commands, including no OSC 11 query for
vim --clean -c qaRelated to #21605
Squashed into one commit, 48cf56f, on the existing upstream base 205b06c
The PR contains no CI configuration changes or unrelated diff performance changes
Review verification
exit_scroll()still emits CR-LF in raw mode becauseout_char()adds the carriage returnThe existing handoff test now checks the newline before
stoptermcap()with a nonemptyt_tithat does not switch screensTemporarily restoring the earlier cooked-mode transition reproduces the late OSC 11 echo, so pending responses must still be handled before that transition
Local validation on macOS arm64
make testpassesTEST_NO_RETRY=1— 1023 tests pass and 16 existing platform or feature checks are skippedt_ti, emptyt_ti, Ex mode, help, and version outputgit diff --check HEAD^ HEADpassesThe first suite run failed in
Test_redirect_Ctrl_CandTest_WinScrolledEach passes three targeted runs on the updated binary, followed by two passing complete startup and autocmd runs without code changes
The Ctrl-C timeout also reproduces three times on the previous-head binary
Full GUI suites, Windows, ASan, and the full Huge test suite were not run locally
Linux clipboard verification
The earlier Clang run failed in
Test_clipmethod_order()with expectedx11, actualnone, and skipped its coverage uploadIts four startup background tests passed
On Colima with Ubuntu 26.04 arm64 and Clang 21, both this source tree and upstream base 205b06c build successfully
Each passes 20 targeted clipboard-order runs and three complete clipboard suites with
TEST_NO_RETRY=1, totaling 70 test executions without skipsThe x86_64 Clang 23 CI failure was not reproduced locally
Commit 48cf56f refreshes only commit metadata to trigger another CI run after the upstream rerun API returned HTTP 403
Its source tree is identical to 3a39bd1, preserving the single-commit structure without changing code, assertions, or workflow configuration
GitHub CI for 48cf56f85 has completed, with all 40 PR checks reported successful and none pending
The Linux huge Clang job passes the clipboard-order test, all four startup background tests, and its coverage generation and upload steps
Project coverage is 82.44% against the 82.42% base, and patch coverage is 93.33%
The GTK4 log still times out in
Test_cscopeWithCscopeConnections()after 20 minutes, as it did in the previous runIts successful check status comes from the repository's existing
continue-on-errorpolicy and does not establish that the complete GTK4 suite passed