patch 9.1.1078: Terminal ansi colors off by one after tgc reset

Commit: 
https://github.com/vim/vim/commit/cde8ff63e2b90ee304bc2e86d9d5e7e20068c79b
Author: Julio B <julio.ba...@gmail.com>
Date:   Thu Feb 6 20:31:27 2025 +0100

    patch 9.1.1078: Terminal ansi colors off by one after tgc reset
    
    Problem:  Terminal ansi colors off by one after tgc reset
    Solution: Set the correct index for libvterm palette,
              revert parts in libvterm/src/pen.c that deviated from upstream
              (Julio B)
    
    fixes: #16568
    closes: #16573
    related: Vim patch v8.2.0804
    
    Co-authored-by: Christian Brabandt <c...@256bit.org>
    Signed-off-by: Julio B <julio.ba...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/libvterm/src/pen.c b/src/libvterm/src/pen.c
index ddc8e40a7..33d3dae9f 100644
--- a/src/libvterm/src/pen.c
+++ b/src/libvterm/src/pen.c
@@ -275,10 +275,7 @@ void vterm_state_set_default_colors(VTermState *state, 
const VTermColor *default
 void vterm_state_set_palette_color(VTermState *state, int index, const 
VTermColor *col)
 {
   if(index >= 0 && index < 16)
-  {
     state->colors[index] = *col;
-    state->colors[index].index = index + 1;
-  }
 }
 
 void vterm_state_convert_color_to_rgb(const VTermState *state, VTermColor *col)
diff --git a/src/term.c b/src/term.c
index 19913428c..4d30ee1ca 100644
--- a/src/term.c
+++ b/src/term.c
@@ -7494,7 +7494,7 @@ ansi_color2rgb(int nr, char_u *r, char_u *g, char_u *b, 
char_u *ansi_idx)
        *r = ansi_table[nr][0];
        *g = ansi_table[nr][1];
        *b = ansi_table[nr][2];
-       *ansi_idx = nr;
+       *ansi_idx = nr + 1;
     }
     else
     {
diff --git a/src/testdir/dumps/Test_terminal_ansi_reset_tgc.dump 
b/src/testdir/dumps/Test_terminal_ansi_reset_tgc.dump
new file mode 100644
index 000000000..c6f6d728b
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_ansi_reset_tgc.dump
@@ -0,0 +1,12 @@
+|$+0&#ffffff0| |p|r|i|n|t|f| |'|\|0|3@1|[|0|;|3|0|;|4|1|m|h|e|l@1|o| 
|w|o|r|l|d|\|0|3@1|[|0|m|\|n|'| @30
+|h+0#0000001#e000002|e|l@1|o| |w|o|r|l|d| +0#0000000#ffffff0@63
+|$| |p|r|i|n|t|f| |'|\|0|3@1|[|0|;|3|0|;|4|1|m|h|e|l@1|o| 
|w|o|r|l|d|\|0|3@1|[|0|m|\|n|'| @30
+|h+0#0000001#e000002|e|l@1|o| |w|o|r|l|d| +0#0000000#ffffff0@63
+|$| > @72
+|!+2#ffffff16#00e0003|s|h| |[|r|u|n@1|i|n|g|]| @43|1|,|1| @11|A|l@1
+| +0#0000000#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+| +0&&@74
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 5343efb95..b53f0cd53 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -2149,6 +2149,30 @@ func Test_terminal_ansicolors_default()
   exe buf . 'bwipe'
 endfunc
 
+func Test_terminal_ansicolors_default_reset_tgc()
+  CheckFeature termguicolors
+  CheckRunVimInTerminal
+
+  let $PS1="$ "
+  let buf = RunVimInTerminal('-c "term sh"', {'rows': 12})
+  call TermWait(buf)
+  " Wait for the shell to display a prompt
+  call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
+
+  call term_sendkeys(buf, "printf '\033[0;30;41mhello world\033[0m\n'\<CR>")
+  call WaitForAssert({-> assert_match('hello world', term_getline(buf, 2))})
+  call term_sendkeys(buf, "\<C-W>:set notgc\<CR>")
+  call term_sendkeys(buf, "printf '\033[0;30;41mhello world\033[0m\n'\<CR>")
+  call WaitForAssert({-> assert_match('hello world', term_getline(buf, 4))})
+
+  call VerifyScreenDump(buf, 'Test_terminal_ansi_reset_tgc', {})
+
+  call term_sendkeys(buf, "exit\<CR>")
+  call TermWait(buf)
+  call StopVimInTerminal(buf)
+  unlet! $PS1
+endfunc
+
 let s:test_colors = [
        \ '#616e64', '#0d0a79',
        \ '#6d610d', '#0a7373',
diff --git a/src/version.c b/src/version.c
index c51a07daa..521fc8323 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1078,
 /**/
     1077,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1tg7oC-00An2k-63%40256bit.org.

Raspunde prin e-mail lui