comparison src/term.c @ 13314:65c3e8259124 v8.0.1531

patch 8.0.1531: cannot use 24 bit colors in MS-Windows console commit https://github.com/vim/vim/commit/cafafb381a04e33f3ce9cd15dd9f94b73226831f Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 22 21:07:09 2018 +0100 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console Problem: Cannot use 24 bit colors in MS-Windows console. Solution: Add support for vcon. (Nobuhiro Takasaki, Ken Takasaki, fixes #1270, fixes #2060)
author Christian Brabandt <cb@256bit.org>
date Thu, 22 Feb 2018 21:15:05 +0100
parents ac42c4b11dbc
children de19318319a6
comparison
equal deleted inserted replaced
13313:97fb19f36653 13314:65c3e8259124
74 /* start of keys that are not directly used by Vim but can be mapped */ 74 /* start of keys that are not directly used by Vim but can be mapped */
75 #define BT_EXTRA_KEYS 0x101 75 #define BT_EXTRA_KEYS 0x101
76 76
77 static struct builtin_term *find_builtin_term(char_u *name); 77 static struct builtin_term *find_builtin_term(char_u *name);
78 static void parse_builtin_tcap(char_u *s); 78 static void parse_builtin_tcap(char_u *s);
79 static void term_color(char_u *s, int n);
80 static void gather_termleader(void); 79 static void gather_termleader(void);
81 #ifdef FEAT_TERMRESPONSE 80 #ifdef FEAT_TERMRESPONSE
82 static void req_codes_from_term(void); 81 static void req_codes_from_term(void);
83 static void req_more_codes_from_term(void); 82 static void req_more_codes_from_term(void);
84 static void got_code_from_term(char_u *code, int len); 83 static void got_code_from_term(char_u *code, int len);
597 {(int)KS_TE, "\033|E"}, /* out of termcap mode */ 596 {(int)KS_TE, "\033|E"}, /* out of termcap mode */
598 # ifdef TERMINFO 597 # ifdef TERMINFO
599 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"},/* scroll region */ 598 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"},/* scroll region */
600 # else 599 # else
601 {(int)KS_CS, "\033|%i%d;%dr"},/* scroll region */ 600 {(int)KS_CS, "\033|%i%d;%dr"},/* scroll region */
601 # endif
602 # ifdef FEAT_TERMGUICOLORS
603 {(int)KS_8F, "\033|38;2;%lu;%lu;%lum"},
604 {(int)KS_8B, "\033|48;2;%lu;%lu;%lum"},
602 # endif 605 # endif
603 606
604 {K_UP, "\316H"}, 607 {K_UP, "\316H"},
605 {K_DOWN, "\316P"}, 608 {K_DOWN, "\316P"},
606 {K_LEFT, "\316K"}, 609 {K_LEFT, "\316K"},
2005 2008
2006 #ifdef FEAT_TERMRESPONSE 2009 #ifdef FEAT_TERMRESPONSE
2007 may_req_termresponse(); 2010 may_req_termresponse();
2008 #endif 2011 #endif
2009 2012
2013 #if defined(WIN3264) && !defined(FEAT_GUI) && defined(FEAT_TERMGUICOLORS)
2014 if (STRCMP(term, "win32") == 0)
2015 set_color_count((p_tgc) ? 256 : 16);
2016 #endif
2017
2010 return OK; 2018 return OK;
2011 } 2019 }
2012 2020
2013 #if defined(FEAT_MOUSE) || defined(PROTO) 2021 #if defined(FEAT_MOUSE) || defined(PROTO)
2014 2022
2816 { 2824 {
2817 OUT_STR(tgoto((char *)T_CWS, width, height)); 2825 OUT_STR(tgoto((char *)T_CWS, width, height));
2818 } 2826 }
2819 #endif 2827 #endif
2820 2828
2821 void
2822 term_fg_color(int n)
2823 {
2824 /* Use "AF" termcap entry if present, "Sf" entry otherwise */
2825 if (*T_CAF)
2826 term_color(T_CAF, n);
2827 else if (*T_CSF)
2828 term_color(T_CSF, n);
2829 }
2830
2831 void
2832 term_bg_color(int n)
2833 {
2834 /* Use "AB" termcap entry if present, "Sb" entry otherwise */
2835 if (*T_CAB)
2836 term_color(T_CAB, n);
2837 else if (*T_CSB)
2838 term_color(T_CSB, n);
2839 }
2840
2841 static void 2829 static void
2842 term_color(char_u *s, int n) 2830 term_color(char_u *s, int n)
2843 { 2831 {
2844 char buf[20]; 2832 char buf[20];
2845 int i = 2; /* index in s[] just after <Esc>[ or CSI */ 2833 int i = *s == CSI ? 1 : 2;
2834 /* index in s[] just after <Esc>[ or CSI */
2846 2835
2847 /* Special handling of 16 colors, because termcap can't handle it */ 2836 /* Special handling of 16 colors, because termcap can't handle it */
2848 /* Also accept "\e[3%dm" for TERMINFO, it is sometimes used */ 2837 /* Also accept "\e[3%dm" for TERMINFO, it is sometimes used */
2849 /* Also accept CSI instead of <Esc>[ */ 2838 /* Also accept CSI instead of <Esc>[ */
2850 if (n >= 8 && t_colors >= 16 2839 if (n >= 8 && t_colors >= 16
2865 : (n >= 16 ? "48;5;" : "10")); 2854 : (n >= 16 ? "48;5;" : "10"));
2866 OUT_STR(tgoto(buf, 0, n >= 16 ? n : n - 8)); 2855 OUT_STR(tgoto(buf, 0, n >= 16 ? n : n - 8));
2867 } 2856 }
2868 else 2857 else
2869 OUT_STR(tgoto((char *)s, 0, n)); 2858 OUT_STR(tgoto((char *)s, 0, n));
2859 }
2860
2861 void
2862 term_fg_color(int n)
2863 {
2864 /* Use "AF" termcap entry if present, "Sf" entry otherwise */
2865 if (*T_CAF)
2866 term_color(T_CAF, n);
2867 else if (*T_CSF)
2868 term_color(T_CSF, n);
2869 }
2870
2871 void
2872 term_bg_color(int n)
2873 {
2874 /* Use "AB" termcap entry if present, "Sb" entry otherwise */
2875 if (*T_CAB)
2876 term_color(T_CAB, n);
2877 else if (*T_CSB)
2878 term_color(T_CSB, n);
2870 } 2879 }
2871 2880
2872 #if defined(FEAT_TERMGUICOLORS) || defined(PROTO) 2881 #if defined(FEAT_TERMGUICOLORS) || defined(PROTO)
2873 2882
2874 #define RED(rgb) (((long_u)(rgb) >> 16) & 0xFF) 2883 #define RED(rgb) (((long_u)(rgb) >> 16) & 0xFF)
6612 else if (p->bt_entry == (int)KS_MD) 6621 else if (p->bt_entry == (int)KS_MD)
6613 p->bt_string = &ksmd_str[0]; 6622 p->bt_string = &ksmd_str[0];
6614 ++p; 6623 ++p;
6615 } 6624 }
6616 } 6625 }
6626
6627 struct ks_tbl_s
6628 {
6629 int code; /* value of KS_ */
6630 char *vtp; /* code in vtp mode */
6631 char *buf; /* buffer in non-vtp mode */
6632 char *vbuf; /* buffer in vtp mode */
6633 };
6634
6635 static struct ks_tbl_s ks_tbl[] =
6636 {
6637 {(int)KS_ME, "\033|0m" }, /* normal */
6638 {(int)KS_MR, "\033|7m" }, /* reverse */
6639 {(int)KS_MD, "\033|1m" }, /* bold */
6640 {(int)KS_SO, "\033|91m"}, /* standout: bright red text */
6641 {(int)KS_SE, "\033|39m"}, /* standout end: default color */
6642 {(int)KS_CZH, "\033|95m"}, /* italic: bright magenta text */
6643 {(int)KS_CZR, "\033|0m",}, /* italic end */
6644 {(int)KS_US, "\033|4m",}, /* underscore */
6645 {(int)KS_UE, "\033|24m"}, /* underscore end */
6646 {(int)KS_NAME, NULL}
6647 };
6648
6649 static struct builtin_term *
6650 find_first_tcap(
6651 char_u *name,
6652 int code)
6653 {
6654 struct builtin_term *p;
6655
6656 p = find_builtin_term(name);
6657 while (p->bt_string != NULL)
6658 {
6659 if (p->bt_entry == code)
6660 return p;
6661 p++;
6662 }
6663 return NULL;
6664 }
6665
6666 /*
6667 * For Win32 console: replace the sequence immediately after termguicolors.
6668 */
6669 void
6670 swap_tcap(void)
6671 {
6672 # ifdef FEAT_TERMGUICOLORS
6673 static int init = 0;
6674 static int last_tgc;
6675 struct ks_tbl_s *ks;
6676 struct builtin_term *bt;
6677
6678 /* buffer initialization */
6679 if (init == 0)
6680 {
6681 ks = ks_tbl;
6682 while (ks->vtp != NULL)
6683 {
6684 bt = find_first_tcap(DEFAULT_TERM, ks->code);
6685 ks->buf = bt->bt_string;
6686 ks->vbuf = ks->vtp;
6687 ks++;
6688 }
6689 init++;
6690 last_tgc = p_tgc;
6691 return;
6692 }
6693
6694 if (last_tgc != p_tgc)
6695 {
6696 if (p_tgc)
6697 {
6698 /* switch to special character sequence */
6699 ks = ks_tbl;
6700 while (ks->vtp != NULL)
6701 {
6702 bt = find_first_tcap(DEFAULT_TERM, ks->code);
6703 ks->buf = bt->bt_string;
6704 bt->bt_string = ks->vbuf;
6705 ks++;
6706 }
6707 }
6708 else
6709 {
6710 /* switch to index color */
6711 ks = ks_tbl;
6712 while (ks->vtp != NULL)
6713 {
6714 bt = find_first_tcap(DEFAULT_TERM, ks->code);
6715 ks->vbuf = bt->bt_string;
6716 bt->bt_string = ks->buf;
6717 ks++;
6718 }
6719 }
6720
6721 last_tgc = p_tgc;
6722 }
6723 # endif
6724 }
6725
6617 #endif 6726 #endif
6618 6727
6619 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) 6728 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO)
6620 static int 6729 static int
6621 hex_digit(int c) 6730 hex_digit(int c)