Adds an autocommand TermResponseOSC and a vim var v:termosc that captures the OSC response. This allows for stuff such as the OSC 52 command. Currently can't capture responses larger than the typeahead buffer, I am working on it.
https://github.com/vim/vim/pull/17975
(4 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
fixes: #14995 ?
@chrisbra Is there an equivalent to gettimeofday() in Windows that should be used in the code base?
It seems this is available
https://github.com/vim/vim/blob/397b9da29d29a96d92ebdfd9d6bf379249519fa1/src/time.c#L950-L962
Thanks for working on it. It seems you really enjoy working on not so small issues! 🙇♂️
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 2 commits.
You are receiving this because you are subscribed to this thread.![]()
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
https://github.com/vim/vim/blob/397b9da29d29a96d92ebdfd9d6bf379249519fa1/src/time.c#L950-L962
I'm guessing I can make that non-static to be used elsewhere?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
I'm guessing I can make that non-static to be used elsewhere?
of course, if that makes sense.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 2 commits.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
I think this is ready for review
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@chrisbra commented on this pull request.
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?
In src/testdir/test_termcodes.vim:
> @@ -2803,4 +2735,21 @@ func Test_xterm_direct_no_termguicolors()
close
endfunc
+" Test if OSC terminal responses are captured correctly
+func Test_term_response_osc()
+ if !has("termresponseosc")
⬇️ Suggested change
- if !has("termresponseosc")
+ CheckFeature termresponseosc
In src/evalvars.c:
> @@ -141,8 +141,8 @@ static struct vimvar
{VV_NAME("t_blob", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("t_class", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("t_object", VAR_NUMBER), NULL, VV_RO},
- {VV_NAME("termrfgresp", VAR_STRING), NULL, VV_RO},
- {VV_NAME("termrbgresp", VAR_STRING), NULL, VV_RO},
+ {VV_NAME("termrfgresp", VAR_STRING), NULL, 0},
+ {VV_NAME("termrbgresp", VAR_STRING), NULL, 0},
why those changes? That looks unrelated to the OSC autocommand
> <amatch> will be set to any of: "version", "cursorblink", "cursorshape", - "background", - "foreground",
What is the thing with Foreground and Background? It won't no longer be handled as part of the TermResponseAll auto command? That would be a backwards incompatible change. Hm, it seems to be handled as part of the new TermResponseOSC autocommand now, hmm...
> "ambiguouswidth" Note that this event may be triggered halfway executing another event, especially if file I/O, a shell command or anything else that takes time + is involved. + *TermResponseOSC* +TermResponseOSC + After a response was received from the + terminal from a previous OSC command that was + sent. The value of |v:termosc| will be set to + the response data. The OSC response must have + a terminator (see |v:termosc|), or Vim will + timeout after 'osctimeoutlen' milliseconds + waiting for one. To see how this event can be + used, look at the colorresp.vim plugin + included with Vim.⬇️ Suggested change
- included with Vim. + included with Vim. + Note: TermResponseOSC will also be triggered for requested terminal foreground and background color |v:termrbgresp| |v:termrfgresp|.
Something like this to note that this now handles the terminal request colors?
In src/errors.h:
> @@ -3782,3 +3782,5 @@ EXTERN char e_duplicate_type_var_name_str[]
EXTERN char e_diff_anchors_with_hidden_windows[]
INIT(= N_("E1562: Diff anchors cannot be used with hidden diff windows"));
#endif
+EXTERN char e_osc_response_timed_out[]
+ INIT(= N_("E1563: OSC command response timed out: %.*s"));
can you please regenerate vim.pot in the po directory?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@Copilot commented on this pull request.
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:
EVENT_TERMRESPONSEOSC autocommand and VV_TERMOSC variable for OSC response handlingosctimeoutlen option to control OSC response timeout behaviorCopilot 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.
In src/structs.h:
> @@ -1290,6 +1290,19 @@ typedef struct
#endif
} tasave_T;
+// Holds state for current OSC response.
+typedef struct
+{
+ int processing; // If we are in the middle of an OSC response
+ char_u start_char; // First char in the OSC response
+ garray_T buf; // Buffer holding the OSC response, to be
+ // placed in the "v:vimosc" vim var.
The comment has a typo: 'vimosc' should be 'termosc' to match the actual variable name v:termosc.
⬇️ Suggested change- // placed in the "v:vimosc" vim var. + // placed in the "v:termosc" vim var.
> @@ -2911,6 +2910,15 @@ v:termu7resp The escape sequence returned by the terminal for the |t_u7| this option is set, the TermResponseAll autocommand event is fired, with <amatch> set to "ambiguouswidth". + *v:termosc* +v:termosc The data of the most recent OSC response received from the + terminal, without including the OSC identifier (<Esc>] or + character <0x9d>) and the OSC terminator, which can either be + a string terminator character <0x9c>, <Esc>\, or a bell + character. + When this option is set, the |TermResponseOSC| autocoomand event
There's a typo: 'autocoomand' should be 'autocommand'.
⬇️ Suggested change- When this option is set, the |TermResponseOSC| autocoomand event + When this option is set, the |TermResponseOSC| autocommand event
In runtime/plugin/colorresp.vim:
> @@ -0,0 +1,41 @@ +vim9script + +# Vim plugin for setting the and background and foreground colours depending on
There's a grammatical error: 'setting the and background' should be 'setting the background'.
⬇️ Suggested change-# Vim plugin for setting the and background and foreground colours depending on +# Vim plugin for setting the background and foreground colours depending on
In src/time.c:
> @@ -127,6 +127,20 @@ get_ctime(time_t thetime, int add_newline)
return buf;
}
+#if defined(MSWIN) || defined(__MINGW32__)
+/*
+ * Windows doesn't have gettimeofday(), although it does have struct timeval.
+ */
+ int
+gettimeofday(struct timeval *tv, char *dummy UNUSED)
The gettimeofday function is moved to global scope but lacks a header declaration. This could cause compilation warnings or errors when the function is used elsewhere.
In src/term.c:
> - || argp[2] != ';'))
- i = 0; // no match
+ if (!osc_state.processing)
+ {
+ // Check if it is a valid OSC sequence, and consume it. OSC format
+ // consists of:
+ // <idenfitifer><data><terminator>
+ // <identifier> is either <Esc>] or an OSC character
+ // <terminator> can be '\007', <Esc>\ or STERM.
+ cur = 1 + (tp[0] == ESC);
+
+ if (len < cur + 1 + (tp[0] != OSC)) // Include terminator as well
+ return FAIL;
+
+ // The whole OSC response may be larger than the typeahead buffer.
+ // To handle this, keep reading data in and out of the typahead
There's a typo: 'typahead' should be 'typeahead'.
⬇️ Suggested change- // To handle this, keep reading data in and out of the typahead + // To handle this, keep reading data in and out of the typeahead
In src/term.c:
> else
- for (i = j; i < len; ++i)
- if (tp[i] == '\007' || (tp[0] == OSC ? tp[i] == STERM
- : (tp[i] == ESC && i + 1 < len && tp[i + 1] == '\\')))
- {
- int is_bg = argp[1] == '1';
- int is_4digit = i - j >= 21 && tp[j + 11] == '/'
- && tp[j + 16] == '/';
+ last_char = ((char_u *)osc_state.buf.ga_data)[osc_state.buf.ga_len - 1];
+
+ key_name[0] = (int)KS_EXTRA;
+ key_name[1] = (int)KE_IGNORE;
+
+ // Read data and append to buffer. If we reach a terminator, then
+ // finally set the vim var.
+ for (int i = cur; i < len; i++)
[nitpick] Variable declaration inside for loop may not be compatible with older C standards. Consider declaring 'i' at the beginning of the function for better compatibility.
⬇️ Suggested change- for (int i = cur; i < len; i++) + for (i = cur; i < len; i++)
In runtime/plugin/colorresp.vim:
> + finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+ au!
+ au TermResponseOSC * {
+ var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+ if len(parts) >= 5
+ var type: string = parts[1]
+ var rval: number = str2nr(parts[2][: 1], 16)
+ var gval: number = str2nr(parts[3][: 1], 16)
+ var bval: number = str2nr(parts[4][: 1], 16)
+
+ if type == '11'
+ var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
The magic number '6' and the formula for determining light/dark background is unclear. Consider adding a comment explaining the logic or extracting this into a named constant.
⬇️ Suggested change- var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
+ # Determine if the background color is "light" or "dark" by comparing the sum of the first hex digit of each RGB component
+ # to a threshold. 'char2nr("6")' is used as an approximate midpoint for a single hex digit (0-F), so 3 * char2nr("6") is the threshold.
+ const RGB_LIGHTNESS_THRESHOLD = 3 * char2nr('6')
+ var new_bg_val: string = (RGB_LIGHTNESS_THRESHOLD < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
In src/evalvars.c:
> @@ -141,8 +141,8 @@ static struct vimvar
{VV_NAME("t_blob", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("t_class", VAR_NUMBER), NULL, VV_RO},
{VV_NAME("t_object", VAR_NUMBER), NULL, VV_RO},
- {VV_NAME("termrfgresp", VAR_STRING), NULL, VV_RO},
- {VV_NAME("termrbgresp", VAR_STRING), NULL, VV_RO},
+ {VV_NAME("termrfgresp", VAR_STRING), NULL, 0},
+ {VV_NAME("termrbgresp", VAR_STRING), NULL, 0},
I made them read writable so that the colorresp.vim plugin can set them for backwards compatibility
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> <amatch> will be set to any of: "version", "cursorblink", "cursorshape", - "background", - "foreground",
there was originally a handle_osc() function that specifically handled OSC responses related to terminal foreground/background colour detection. Now that has been moved to Vimscript. Maybe the colorresp.vim plugin can use doautocmd to emit a TermResponseAll event for backwards compatibility?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
> "ambiguouswidth" Note that this event may be triggered halfway executing another event, especially if file I/O, a shell command or anything else that takes time + is involved. + *TermResponseOSC* +TermResponseOSC + After a response was received from the + terminal from a previous OSC command that was + sent. The value of |v:termosc| will be set to + the response data. The OSC response must have + a terminator (see |v:termosc|), or Vim will + timeout after 'osctimeoutlen' milliseconds + waiting for one. To see how this event can be + used, look at the colorresp.vim plugin + included with Vim.
This PR treats the terminal colour responses like any other OSC response. Its just that the colorresp.vim plugin does the work that the original c code did
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@chrisbra commented on this pull request.
> <amatch> will be set to any of: "version", "cursorblink", "cursorshape", - "background", - "foreground",
yeah, that should work I guess.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> <amatch> will be set to any of: "version", "cursorblink", "cursorshape", - "background", - "foreground",
Ok I did that and it seems to work, so I guess this is resolved?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
In runtime/plugin/colorresp.vim:
> + finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+ au!
+ au TermResponseOSC * {
+ var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+ if len(parts) >= 5
+ var type: string = parts[1]
+ var rval: number = str2nr(parts[2][: 1], 16)
+ var gval: number = str2nr(parts[3][: 1], 16)
+ var bval: number = str2nr(parts[4][: 1], 16)
+
+ if type == '11'
+ var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
To be honest I don't know how this works really, I just copied it from the original C code and translated to Vimscript and it passes the tests so I guess it works
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
In src/time.c:
> @@ -127,6 +127,20 @@ get_ctime(time_t thetime, int add_newline)
return buf;
}
+#if defined(MSWIN) || defined(__MINGW32__)
+/*
+ * Windows doesn't have gettimeofday(), although it does have struct timeval.
+ */
+ int
+gettimeofday(struct timeval *tv, char *dummy UNUSED)
Copilot doesn't know its in the time.pro file?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
Thanks. Can you please also update
$VIMRUNTIME/optwin.vimand regenerate the vim syntax script?cd runtime/syntax/generator && make.
Done
Also I think we should document the new plugin colorresp.vim somewhere.
I'm not sure where to document it though. This plugin is similar to the rrhelper.vim plugin (which doesn't have documentation), so I'm not sure if documentation is necessary
I am also wondering if not using the autocommand
TermResponseALLwith<amatch>set to e.g.oscwould be better and backwards compatible?
I think its better to have separate autocommand TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Thanks. Can you please also update
$VIMRUNTIME/optwin.vimand regenerate the vim syntax script?cd runtime/syntax/generator && make.Done
Also I think we should document the new plugin colorresp.vim somewhere.
I'm not sure where to document it though. This plugin is similar to the rrhelper.vim plugin (which doesn't have documentation), so I'm not sure if documentation is necessary
Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.
I am also wondering if not using the autocommand
TermResponseALLwith<amatch>set to e.g.oscwould be better and backwards compatible?I think its better to have separate autocommand
TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility
Okay
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.
I'm not sure what you mean, can you elaborate?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
Yeah, also not sure. Hm, let's then just make it explicit in the help, like $VIMRUNTIME/plugin/colorresp.vim so gf on it works.
I'm not sure what you mean, can you elaborate?
Something like this (slightly reworded using ChatGPT):
TermResponseOSC
After a response is received from the terminal for a previously sent
OSC (Operating System Command). The response data is stored in
|v:termosc|. The terminal response must include a terminator
(see |v:termosc|); otherwise, Vim will wait up to
'osctimeoutlen' milliseconds and then timeout.
To see an example of using this event, see
$VIMRUNTIME/plugin/colorresp.vim.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
Something like this (slightly reworded using ChatGPT):
TermResponseOSC After a response is received from the terminal for a previously sent OSC (Operating System Command). The response data is stored in |v:termosc|. The terminal response must include a terminator (see |v:termosc|); otherwise, Vim will wait up to 'osctimeoutlen' milliseconds and then timeout. To see an example of using this event, see $VIMRUNTIME/plugin/colorresp.vim.
Thanks, changed it
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Given that there is already TermResponseAll, should this PR extend it, with being set to osc for example?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
I think its better to have separate autocommand
TermResponseOSC, since TermResponseAll seems to be for specific terminal responses, while TermResponseOSC is for OSC responses in general. Considering that there was no "osc' value for in the first place, I don't think this would affect backwards compatbility
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@chrisbra Actually, I've decided to use TermResponseAll with <amatch> set to osc, It will make more sense if we start handling more types of terminal sequence responses
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
I think this is ready
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@chrisbra commented on this pull request.
> "ambiguouswidth" + "osc"
Note: Traditionally, TermResponseAll was also used for "foreground" and "background" patterns. These are now handled as part of the "osc" value. For backwards compatibility, however, the colorresp.vim plugin will handle "osc" events and emit TermResponseAll autocommand events when it encounters "foreground" and "background" values.
> @@ -2911,6 +2910,12 @@ v:termu7resp The escape sequence returned by the terminal for the |t_u7| this option is set, the TermResponseAll autocommand event is fired, with <amatch> set to "ambiguouswidth". + *v:termosc* +v:termosc The escape sequence of the most recent OSC response received + from the terminal, When this option is set, the + |TermResponseAll| autocommand event is fired, with <amatch> + set to "osc".
Also used to handle "foreground" and "background" terminal responses.
> @@ -2911,6 +2910,12 @@ v:termu7resp The escape sequence returned by the terminal for the |t_u7| this option is set, the TermResponseAll autocommand event is fired, with <amatch> set to "ambiguouswidth". + *v:termosc* +v:termosc The escape sequence of the most recent OSC response received + from the terminal, When this option is set, the⬇️ Suggested change
- from the terminal, When this option is set, the + from the terminal. When this option is set, the
In runtime/plugin/colorresp.vim:
> @@ -0,0 +1,48 @@ +vim9script
The name colorresp is a bit obscure. Should we call it termosc.vim ?
In runtime/plugin/colorresp.vim:
> + finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+ au!
+ au TermResponseOSC * {
+ var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+ if len(parts) >= 5
+ var type: string = parts[1]
+ var rval: number = str2nr(parts[2][: 1], 16)
+ var gval: number = str2nr(parts[3][: 1], 16)
+ var bval: number = str2nr(parts[4][: 1], 16)
+
+ if type == '11'
+ var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
So let's add a comment like this:
" Detect light or dark background by parsing OSC 11 RGB background reply from terminal.
" Sum the RGB values roughly; if bright enough, set 'background' to 'light',
" otherwise set it to 'dark'.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@chrisbra commented on this pull request.
I have a few additional comments. What do you think?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
I think that is a somewhat broad name for the usecase of the plugin. Maybe it should be colorresponse.vim?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
> + finish
+endif
+g:loaded_colorresp = 1
+
+augroup ColorResp
+ au!
+ au TermResponseOSC * {
+ var parts: list<string> = matchlist(v:termosc, '\(\d\+\);rgb:\(\w\+\)/\(\w\+\)/\(\w\+\)')
+ if len(parts) >= 5
+ var type: string = parts[1]
+ var rval: number = str2nr(parts[2][: 1], 16)
+ var gval: number = str2nr(parts[3][: 1], 16)
+ var bval: number = str2nr(parts[4][: 1], 16)
+
+ if type == '11'
+ var new_bg_val: string = (3 * char2nr('6') < char2nr(parts[2]) + char2nr(parts[3]) + char2nr(parts[4])) ? "light" : "dark"
Okay, will do
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
I think this is ready
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
can you please rebase?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
can you please rebase?
Done
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
thanks
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman this PR breaks Windows Terminal, could you please take a look at: #18251
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@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?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
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.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
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?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
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 = 1to your vimrc and see if that fixes it?
Your solution works. adding let g:loaded_colorresp = 1 did fix the problem.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()