Mercurial > vim
comparison src/term.c @ 31557:e487df006ae1 v9.0.1111
patch 9.0.1111: termcap entries for RGB colors are not set automatically
Commit: https://github.com/vim/vim/commit/96dd34e53492913029323dad902831380fa460d0
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Dec 30 11:16:00 2022 +0000
patch 9.0.1111: termcap entries for RGB colors are not set automatically
Problem: Termcap entries for RGB colors are not set automatically.
Solution: Always set the termcap entries when +termguicolors is enabled.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 30 Dec 2022 12:30:03 +0100 |
parents | b9a4699d6a35 |
children | ef9591271746 |
comparison
equal
deleted
inserted
replaced
31556:d01fe76a049b | 31557:e487df006ae1 |
---|---|
474 # endif | 474 # endif |
475 {(int)KS_CRV, "\033[>c"}, | 475 {(int)KS_CRV, "\033[>c"}, |
476 {(int)KS_RFG, "\033]10;?\007"}, | 476 {(int)KS_RFG, "\033]10;?\007"}, |
477 {(int)KS_RBG, "\033]11;?\007"}, | 477 {(int)KS_RBG, "\033]11;?\007"}, |
478 {(int)KS_U7, "\033[6n"}, | 478 {(int)KS_U7, "\033[6n"}, |
479 # ifdef FEAT_TERMGUICOLORS | |
480 // These are printf strings, not terminal codes. | |
481 {(int)KS_8F, "\033[38;2;%lu;%lu;%lum"}, | |
482 {(int)KS_8B, "\033[48;2;%lu;%lu;%lum"}, | |
483 {(int)KS_8U, "\033[58;2;%lu;%lu;%lum"}, | |
484 # endif | |
485 {(int)KS_CAU, "\033[58;5;%dm"}, | 479 {(int)KS_CAU, "\033[58;5;%dm"}, |
486 {(int)KS_CBE, "\033[?2004h"}, | 480 {(int)KS_CBE, "\033[?2004h"}, |
487 {(int)KS_CBD, "\033[?2004l"}, | 481 {(int)KS_CBD, "\033[?2004l"}, |
488 {(int)KS_CST, "\033[22;2t"}, | 482 {(int)KS_CST, "\033[22;2t"}, |
489 {(int)KS_CRT, "\033[23;2t"}, | 483 {(int)KS_CRT, "\033[23;2t"}, |
624 // have been used. | 618 // have been used. |
625 {(int)KS_CTE, "\033[>4;m\033[=0;1u"}, | 619 {(int)KS_CTE, "\033[>4;m\033[=0;1u"}, |
626 | 620 |
627 {(int)KS_NAME, NULL} // end marker | 621 {(int)KS_NAME, NULL} // end marker |
628 }; | 622 }; |
623 | |
624 #ifdef FEAT_TERMGUICOLORS | |
625 /* | |
626 * Additions for using the RGB colors | |
627 */ | |
628 static tcap_entry_T builtin_rgb[] = { | |
629 // These are printf strings, not terminal codes. | |
630 {(int)KS_8F, "\033[38;2;%lu;%lu;%lum"}, | |
631 {(int)KS_8B, "\033[48;2;%lu;%lu;%lum"}, | |
632 {(int)KS_8U, "\033[58;2;%lu;%lu;%lum"}, | |
633 | |
634 {(int)KS_NAME, NULL} // end marker | |
635 }; | |
636 #endif | |
629 | 637 |
630 /* | 638 /* |
631 * iris-ansi for Silicon Graphics machines. | 639 * iris-ansi for Silicon Graphics machines. |
632 */ | 640 */ |
633 static tcap_entry_T builtin_iris_ansi[] = { | 641 static tcap_entry_T builtin_iris_ansi[] = { |
889 {(int)KS_TE, "\033|E"}, // out of termcap mode | 897 {(int)KS_TE, "\033|E"}, // out of termcap mode |
890 # ifdef TERMINFO | 898 # ifdef TERMINFO |
891 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"}, // scroll region | 899 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"}, // scroll region |
892 # else | 900 # else |
893 {(int)KS_CS, "\033|%i%d;%dr"}, // scroll region | 901 {(int)KS_CS, "\033|%i%d;%dr"}, // scroll region |
894 # endif | |
895 # ifdef FEAT_TERMGUICOLORS | |
896 {(int)KS_8F, "\033|38;2;%lu;%lu;%lum"}, | |
897 {(int)KS_8B, "\033|48;2;%lu;%lu;%lum"}, | |
898 # endif | 902 # endif |
899 | 903 |
900 {K_UP, "\316H"}, | 904 {K_UP, "\316H"}, |
901 {K_DOWN, "\316P"}, | 905 {K_DOWN, "\316P"}, |
902 {K_LEFT, "\316K"}, | 906 {K_LEFT, "\316K"}, |
1672 "@7", "kP", "kN", "K1", "K3", "K4", "K5", "kB", | 1676 "@7", "kP", "kN", "K1", "K3", "K4", "K5", "kB", |
1673 NULL | 1677 NULL |
1674 }; | 1678 }; |
1675 #endif | 1679 #endif |
1676 | 1680 |
1681 /* | |
1682 * Return TRUE if "term_strings[idx]" was not set. | |
1683 */ | |
1684 static int | |
1685 term_strings_not_set(enum SpecialKey idx) | |
1686 { | |
1687 return TERM_STR(idx) == NULL || TERM_STR(idx) == empty_option; | |
1688 } | |
1689 | |
1677 #ifdef HAVE_TGETENT | 1690 #ifdef HAVE_TGETENT |
1678 /* | 1691 /* |
1679 * Get the termcap entries we need with tgetstr(), tgetflag() and tgetnum(). | 1692 * Get the termcap entries we need with tgetstr(), tgetflag() and tgetnum(). |
1680 * "invoke_tgetent()" must have been called before. | 1693 * "invoke_tgetent()" must have been called before. |
1681 * If "*height" or "*width" are not zero then use the "li" and "col" entries to | 1694 * If "*height" or "*width" are not zero then use the "li" and "col" entries to |
1728 /* | 1741 /* |
1729 * get output strings | 1742 * get output strings |
1730 */ | 1743 */ |
1731 for (i = 0; string_names[i].name != NULL; ++i) | 1744 for (i = 0; string_names[i].name != NULL; ++i) |
1732 { | 1745 { |
1733 if (TERM_STR(string_names[i].dest) == NULL | 1746 if (term_strings_not_set(string_names[i].dest)) |
1734 || TERM_STR(string_names[i].dest) == empty_option) | |
1735 { | 1747 { |
1736 TERM_STR(string_names[i].dest) = TGETSTR(string_names[i].name, &tp); | 1748 TERM_STR(string_names[i].dest) = TGETSTR(string_names[i].name, &tp); |
1737 #ifdef FEAT_EVAL | 1749 #ifdef FEAT_EVAL |
1738 set_term_option_sctx_idx(string_names[i].name, -1); | 1750 set_term_option_sctx_idx(string_names[i].name, -1); |
1739 #endif | 1751 #endif |
1776 *width = tgetnum("co"); | 1788 *width = tgetnum("co"); |
1777 | 1789 |
1778 /* | 1790 /* |
1779 * Get number of colors (if not done already). | 1791 * Get number of colors (if not done already). |
1780 */ | 1792 */ |
1781 if (TERM_STR(KS_CCO) == NULL || TERM_STR(KS_CCO) == empty_option) | 1793 if (term_strings_not_set(KS_CCO)) |
1782 { | 1794 { |
1783 set_color_count(tgetnum("Co")); | 1795 set_color_count(tgetnum("Co")); |
1784 #ifdef FEAT_EVAL | 1796 #ifdef FEAT_EVAL |
1785 set_term_option_sctx_idx("Co", -1); | 1797 set_term_option_sctx_idx("Co", -1); |
1786 #endif | 1798 #endif |
2067 keyprot_T kpc = match_keyprotocol(term); | 2079 keyprot_T kpc = match_keyprotocol(term); |
2068 if (kpc == KEYPROTOCOL_KITTY) | 2080 if (kpc == KEYPROTOCOL_KITTY) |
2069 apply_builtin_tcap(term, builtin_kitty, TRUE); | 2081 apply_builtin_tcap(term, builtin_kitty, TRUE); |
2070 else if (kpc == KEYPROTOCOL_MOK2) | 2082 else if (kpc == KEYPROTOCOL_MOK2) |
2071 apply_builtin_tcap(term, builtin_mok2, TRUE); | 2083 apply_builtin_tcap(term, builtin_mok2, TRUE); |
2084 | |
2085 #ifdef FEAT_TERMGUICOLORS | |
2086 // There is no good way to detect that the terminal supports RGB | |
2087 // colors. Since these termcap entries are non-standard anyway and | |
2088 // only used when the user sets 'termguicolors' we might as well add | |
2089 // them. But not when one of them was alredy set. | |
2090 if (term_strings_not_set(KS_8F) | |
2091 && term_strings_not_set(KS_8B) | |
2092 && term_strings_not_set(KS_8U)) | |
2093 apply_builtin_tcap(term, builtin_rgb, TRUE); | |
2094 #endif | |
2072 } | 2095 } |
2073 | 2096 |
2074 /* | 2097 /* |
2075 * special: There is no info in the termcap about whether the cursor | 2098 * special: There is no info in the termcap about whether the cursor |
2076 * positioning is relative to the start of the screen or to the start of the | 2099 * positioning is relative to the start of the screen or to the start of the |