comparison src/os_win32.c @ 13823:d0d8125ba692 v8.0.1783

patch 8.0.1783: cannot use 256 colors in a MS-Windows console commit https://github.com/vim/vim/commit/c5cd88554f1e0b2e9ff08d9a0748238dd8340ce1 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 1 15:47:38 2018 +0200 patch 8.0.1783: cannot use 256 colors in a MS-Windows console Problem: Cannot use 256 colors in a MS-Windows console. Solution: Add 256 color support. (Nobuhiro Takasaki, closes https://github.com/vim/vim/issues/2821)
author Christian Brabandt <cb@256bit.org>
date Tue, 01 May 2018 16:00:07 +0200
parents cc7dc249e371
children 27e09f1a8e5c
comparison
equal deleted inserted replaced
13822:46912abff012 13823:d0d8125ba692
212 212
213 static guicolor_T save_console_bg_rgb; 213 static guicolor_T save_console_bg_rgb;
214 static guicolor_T save_console_fg_rgb; 214 static guicolor_T save_console_fg_rgb;
215 215
216 # ifdef FEAT_TERMGUICOLORS 216 # ifdef FEAT_TERMGUICOLORS
217 # define USE_VTP (vtp_working && p_tgc) 217 # define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256)))
218 # else 218 # else
219 # define USE_VTP 0 219 # define USE_VTP 0
220 # endif 220 # endif
221 221
222 static void set_console_color_rgb(void); 222 static void set_console_color_rgb(void);
2628 if (cterm_normal_bg_color == 0) 2628 if (cterm_normal_bg_color == 0)
2629 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1; 2629 cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1;
2630 2630
2631 /* set termcap codes to current text attributes */ 2631 /* set termcap codes to current text attributes */
2632 update_tcap(g_attrCurrent); 2632 update_tcap(g_attrCurrent);
2633 swap_tcap();
2634 2633
2635 GetConsoleCursorInfo(g_hConOut, &g_cci); 2634 GetConsoleCursorInfo(g_hConOut, &g_cci);
2636 GetConsoleMode(g_hConIn, &g_cmodein); 2635 GetConsoleMode(g_hConIn, &g_cmodein);
2637 GetConsoleMode(g_hConOut, &g_cmodeout); 2636 GetConsoleMode(g_hConOut, &g_cmodeout);
2638 2637
5761 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy); 5760 FillConsoleOutputCharacter(g_hConOut, ' ', n, coord, &dwDummy);
5762 5761
5763 if (!USE_VTP) 5762 if (!USE_VTP)
5764 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy); 5763 FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, n, coord, &dwDummy);
5765 else 5764 else
5766 FillConsoleOutputAttribute(g_hConOut, 0, n, coord, &dwDummy); 5765 {
5766 set_console_color_rgb();
5767 gotoxy(coord.X + 1, coord.Y + 1);
5768 vtp_printf("\033[%dX", n);
5769 }
5767 } 5770 }
5768 5771
5769 5772
5770 /* 5773 /*
5771 * Clear the screen 5774 * Clear the screen
7651 *p++ = 'm'; 7654 *p++ = 'm';
7652 *p = NUL; 7655 *p = NUL;
7653 vtp_printf((char *)buf); 7656 vtp_printf((char *)buf);
7654 } 7657 }
7655 7658
7659 static int
7660 ctermtoxterm(
7661 int cterm)
7662 {
7663 uint8_t r, g, b, idx;
7664
7665 cterm_color2rgb(cterm, &r, &g, &b, &idx);
7666 return (((int)r << 16) | ((int)g << 8) | (int)b);
7667 }
7668
7656 static void 7669 static void
7657 set_console_color_rgb(void) 7670 set_console_color_rgb(void)
7658 { 7671 {
7659 # ifdef FEAT_TERMGUICOLORS 7672 # ifdef FEAT_TERMGUICOLORS
7660 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; 7673 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
7661 int id; 7674 int id;
7662 guicolor_T fg = INVALCOLOR; 7675 guicolor_T fg = INVALCOLOR;
7663 guicolor_T bg = INVALCOLOR; 7676 guicolor_T bg = INVALCOLOR;
7677 int ctermfg;
7678 int ctermbg;
7664 7679
7665 if (!USE_VTP) 7680 if (!USE_VTP)
7666 return; 7681 return;
7667 7682
7668 id = syn_name2id((char_u *)"Normal"); 7683 id = syn_name2id((char_u *)"Normal");
7669 if (id > 0) 7684 if (id > 0)
7670 syn_id2colors(id, &fg, &bg); 7685 syn_id2colors(id, &fg, &bg);
7671 if (fg == INVALCOLOR) 7686 if (fg == INVALCOLOR)
7672 fg = 0xc0c0c0; /* white text */ 7687 {
7688 ctermfg = -1;
7689 if (id > 0)
7690 syn_id2cterm_bg(id, &ctermfg, &ctermbg);
7691 fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : 0xc0c0c0; /* white */
7692 }
7673 if (bg == INVALCOLOR) 7693 if (bg == INVALCOLOR)
7674 bg = 0x000000; /* black background */ 7694 {
7695 ctermbg = -1;
7696 if (id > 0)
7697 syn_id2cterm_bg(id, &ctermfg, &ctermbg);
7698 bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : 0x000000; /* black */
7699 }
7675 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg); 7700 fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
7676 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg); 7701 bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
7677 7702
7678 csbi.cbSize = sizeof(csbi); 7703 csbi.cbSize = sizeof(csbi);
7679 if (has_csbiex) 7704 if (has_csbiex)
7728 use_vtp(void) 7753 use_vtp(void)
7729 { 7754 {
7730 return USE_VTP; 7755 return USE_VTP;
7731 } 7756 }
7732 7757
7733 #endif 7758 int
7759 is_term_win32(void)
7760 {
7761 return T_NAME != NULL && STRCMP(T_NAME, "win32") == 0;
7762 }
7763
7764 #endif