Skip to content

feat: add way to handle OSC command responses - #17975

Closed
64-bitman wants to merge 1 commit into
vim:masterfrom
64-bitman:termreponse_osc
Closed

64-bitman wants to merge 1 commit into
vim:masterfrom
64-bitman:termreponse_osc

Conversation

@64-bitman

@64-bitman 64-bitman commented Aug 12, 2025 •

Copy link
Copy Markdown
Member

Adds a new possible value for the <amatch> of TermResponseAll called osc, which sets v:termosc when any OSC response is received. This allows for stuff such as the OSC 52 command. The C implementation of the terminal fore/background OSC color response handling is moved to a Vimscript plugin

@64-bitman
64-bitman force-pushed the termreponse_osc branch 2 times, most recently from 6eb2b4d to 62caad6 Compare August 12, 2025 09:30
@64-bitman

Copy link
Copy Markdown
Member Author

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?

@chrisbra

Copy link
Copy Markdown
Member

fixes: #14995 ?

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?

It seems this is available

vim/src/time.c

Lines 950 to 962 in 397b9da

# ifdef MSWIN
/*
* Windows doesn't have gettimeofday(), although it does have struct timeval.
*/
static int
gettimeofday(struct timeval *tv, char *dummy UNUSED)
{
long t = clock();
tv->tv_sec = t / CLOCKS_PER_SEC;
tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
return 0;
}
# endif

Thanks for working on it. It seems you really enjoy working on not so small issues! 🙇‍♂️

@64-bitman

Copy link
Copy Markdown
Member Author

fixes: #14995 ?

I suppose it kind of fixes it, but we still need to add a OSC 52 Vimscript plugin. I think the best way to add that is to first implement some sort of clipboard provider functionality like Neovim.

@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?

It seems this is available

vim/src/time.c

Lines 950 to 962 in 397b9da

# ifdef MSWIN
/*
* Windows doesn't have gettimeofday(), although it does have struct timeval.
*/
static int
gettimeofday(struct timeval *tv, char *dummy UNUSED)
{
long t = clock();
tv->tv_sec = t / CLOCKS_PER_SEC;
tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
return 0;
}
# endif

I'm guessing I can make that non-static to be used elsewhere?

@chrisbra

Copy link
Copy Markdown
Member

I'm guessing I can make that non-static to be used elsewhere?

of course, if that makes sense.

@64-bitman
64-bitman force-pushed the termreponse_osc branch 12 times, most recently from ace1820 to 44547a5 Compare August 14, 2025 01:47
@64-bitman

Copy link
Copy Markdown
Member Author

I think this is ready for review

@64-bitman
64-bitman marked this pull request as ready for review August 14, 2025 01:48
@64-bitman
64-bitman force-pushed the termreponse_osc branch 3 times, most recently from e047b0a to 1dd6cac Compare August 14, 2025 01:51

@chrisbra chrisbra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Can you please also update $VIMRUNTIME/optwin.vim and regenerate the vim syntax script? cd runtime/syntax/generator && make.

Also I think we should document the new plugin colorresp.vim somewhere.

I am also wondering if not using the autocommand TermResponseALL with <amatch> set to e.g. osc would be better and backwards compatible?

Comment thread src/testdir/test_termcodes.vim Resolved
Comment thread src/evalvars.c Resolved
Comment thread runtime/doc/autocmd.txt Resolved
Comment thread runtime/doc/autocmd.txt Resolved
Comment thread src/errors.h Resolved
@chrisbra
chrisbra requested a review from Copilot August 14, 2025 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a new TermResponseOSC autocommand event and introduces the v:termosc vim variable to capture OSC (Operating System Command) responses from terminals. This enables handling of OSC 52 commands and other terminal responses. The implementation moves the existing C-based terminal foreground/background color response handling to a VimScript plugin (colorresp.vim) that uses the new OSC infrastructure.

Key changes:

  • Introduces EVENT_TERMRESPONSEOSC autocommand and VV_TERMOSC variable for OSC response handling
  • Replaces hardcoded color response parsing with generic OSC response capture mechanism
  • Adds osctimeoutlen option to control OSC response timeout behavior

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/vim.h Adds new autocommand event and vim variable constants
src/term.c Replaces color-specific OSC handling with generic OSC response processing
src/structs.h Defines oscstate_T structure for OSC response state management
src/evalvars.c Implements new vim variable and updates existing color response variables
src/option.c Adds validation for new osctimeoutlen option
runtime/plugin/colorresp.vim New VimScript plugin for terminal color response handling
src/testdir/ Updates tests to reflect the new OSC handling approach

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread src/structs.h Resolved
Comment thread runtime/doc/eval.txt Resolved
Comment thread runtime/plugin/colorresp.vim Resolved
Comment thread src/time.c Resolved
Comment thread src/term.c Resolved
Comment thread src/term.c Resolved
Comment thread runtime/plugin/colorresp.vim Resolved
@64-bitman
64-bitman force-pushed the termreponse_osc branch 7 times, most recently from 203cd3d to 3e6a650 Compare August 16, 2025 18:38
@64-bitman

Copy link
Copy Markdown
Member Author

I think this is ready

Comment thread runtime/doc/autocmd.txt Resolved
Comment thread runtime/doc/eval.txt Resolved
Comment thread runtime/doc/eval.txt Resolved
Comment thread runtime/plugin/colorresp.vim Resolved
Comment thread runtime/plugin/colorresp.vim Resolved

@chrisbra chrisbra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few additional comments. What do you think?

@64-bitman
64-bitman force-pushed the termreponse_osc branch 3 times, most recently from 3c3aedc to 38fc3df Compare August 18, 2025 19:56
@64-bitman

Copy link
Copy Markdown
Member Author

I think this is ready

@chrisbra

Copy link
Copy Markdown
Member

can you please rebase?

@64-bitman

Copy link
Copy Markdown
Member Author

can you please rebase?

Done

@chrisbra

Copy link
Copy Markdown
Member

thanks

sahinf pushed a commit to sahinf/vim that referenced this pull request Sep 7, 2025
Problem:  Cannot react to terminal OSC responses
Solution: Allow TermResponseAll to be triggered by Terminal OSC
          responses (Foxe Chen)

fixes: vim#14995
closes: vim#17975

Signed-off-by: Foxe Chen <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
@skywind3000

Copy link
Copy Markdown

@64-bitman this PR breaks Windows Terminal, could you please take a look at: #18251

@64-bitman

Copy link
Copy Markdown
Member Author

@64-bitman this PR breaks Windows Terminal, could you please take a look at: #18251

I believe #18149 fixed this, can you use the newest version of vim and try again?

@skywind3000

Copy link
Copy Markdown

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.

@64-bitman

Copy link
Copy Markdown
Member Author

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.

Can you add let g:loaded_colorresp = 1 to your vimrc and see if that fixes it?

@skywind3000

skywind3000 commented Sep 9, 2025 •

Copy link
Copy Markdown

I believe #18149 fixed this, can you use the newest version of vim and try again?

It didn't fix at all. Yesterday I updated my vim from 9.1.1640 to 9.1.1740 and found this issue, then located the problem was introduced in this PR.

Can you add let g:loaded_colorresp = 1 to your vimrc and see if that fixes it?

Your solution works. adding let g:loaded_colorresp = 1 did fix the problem. (tested with v9.1.1740)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants