comparison src/terminal.c @ 11822:1e237c5994fc v8.0.0791

patch 8.0.0791: terminal colors depend on the system commit https://github.com/vim/vim/commit/b41bf8e6b45a773456031954bca1bc4212cbffbe Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 28 15:11:38 2017 +0200 patch 8.0.0791: terminal colors depend on the system Problem: Terminal colors depend on the system. Solution: Use the highlight color lookup tables.
author Christian Brabandt <cb@256bit.org>
date Fri, 28 Jul 2017 15:15:04 +0200
parents 0f9780ee4207
children 0cfe4a07c2ad
comparison
equal deleted inserted replaced
11821:5a00d6370ba3 11822:1e237c5994fc
31 * terminal emulator invokes callbacks when its screen content changes. The 31 * terminal emulator invokes callbacks when its screen content changes. The
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a 32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a
33 * while, if the terminal window is visible, the screen contents is drawn. 33 * while, if the terminal window is visible, the screen contents is drawn.
34 * 34 *
35 * TODO: 35 * TODO:
36 * - if 'term' starts witth "xterm" use it for $TERM.
36 * - To set BS correctly, check get_stty(); Pass the fd of the pty. 37 * - To set BS correctly, check get_stty(); Pass the fd of the pty.
37 * - include functions from #1871 38 * - include functions from #1871
38 * - do not store terminal buffer in viminfo. Or prefix term:// ? 39 * - do not store terminal buffer in viminfo. Or prefix term:// ?
39 * - Add a scrollback buffer (contains lines to scroll off the top). 40 * - Add a scrollback buffer (contains lines to scroll off the top).
40 * Can use the buf_T lines, store attributes somewhere else? 41 * Can use the buf_T lines, store attributes somewhere else?
753 /* 754 /*
754 * Reverse engineer the RGB value into a cterm color index. 755 * Reverse engineer the RGB value into a cterm color index.
755 * First color is 1. Return 0 if no match found. 756 * First color is 1. Return 0 if no match found.
756 */ 757 */
757 static int 758 static int
758 color2index(VTermColor *color) 759 color2index(VTermColor *color, int foreground)
759 { 760 {
760 int red = color->red; 761 int red = color->red;
761 int blue = color->blue; 762 int blue = color->blue;
762 int green = color->green; 763 int green = color->green;
763 764
765 /* The argument for lookup_color() is for the color_names[] table. */
764 if (red == 0) 766 if (red == 0)
765 { 767 {
766 if (green == 0) 768 if (green == 0)
767 { 769 {
768 if (blue == 0) 770 if (blue == 0)
769 return 1; /* black */ 771 return lookup_color(0, foreground) + 1; /* black */
770 if (blue == 224) 772 if (blue == 224)
771 return 5; /* blue */ 773 return lookup_color(1, foreground) + 1; /* dark blue */
772 } 774 }
773 else if (green == 224) 775 else if (green == 224)
774 { 776 {
775 if (blue == 0) 777 if (blue == 0)
776 return 3; /* green */ 778 return lookup_color(2, foreground) + 1; /* dark green */
777 if (blue == 224) 779 if (blue == 224)
778 return 7; /* cyan */ 780 return lookup_color(3, foreground) + 1; /* dark cyan */
779 } 781 }
780 } 782 }
781 else if (red == 224) 783 else if (red == 224)
782 { 784 {
783 if (green == 0) 785 if (green == 0)
784 { 786 {
785 if (blue == 0) 787 if (blue == 0)
786 return 2; /* red */ 788 return lookup_color(4, foreground) + 1; /* dark red */
787 if (blue == 224) 789 if (blue == 224)
788 return 6; /* magenta */ 790 return lookup_color(5, foreground) + 1; /* dark magenta */
789 } 791 }
790 else if (green == 224) 792 else if (green == 224)
791 { 793 {
792 if (blue == 0) 794 if (blue == 0)
793 return 4; /* yellow */ 795 return lookup_color(6, foreground) + 1; /* dark yellow / brown */
794 if (blue == 224) 796 if (blue == 224)
795 return 8; /* white */ 797 return lookup_color(8, foreground) + 1; /* white / light grey */
796 } 798 }
797 } 799 }
798 else if (red == 128) 800 else if (red == 128)
799 { 801 {
800 if (green == 128 && blue == 128) 802 if (green == 128 && blue == 128)
801 return 9; /* high intensity black */ 803 return lookup_color(12, foreground) + 1; /* high intensity black / dark grey */
802 } 804 }
803 else if (red == 255) 805 else if (red == 255)
804 { 806 {
805 if (green == 64) 807 if (green == 64)
806 { 808 {
807 if (blue == 64) 809 if (blue == 64)
808 return 10; /* high intensity red */ 810 return lookup_color(20, foreground) + 1; /* light red */
809 if (blue == 255) 811 if (blue == 255)
810 return 14; /* high intensity magenta */ 812 return lookup_color(22, foreground) + 1; /* light magenta */
811 } 813 }
812 else if (green == 255) 814 else if (green == 255)
813 { 815 {
814 if (blue == 64) 816 if (blue == 64)
815 return 12; /* high intensity yellow */ 817 return lookup_color(24, foreground) + 1; /* yellow */
816 if (blue == 255) 818 if (blue == 255)
817 return 16; /* high intensity white */ 819 return lookup_color(26, foreground) + 1; /* white */
818 } 820 }
819 } 821 }
820 else if (red == 64) 822 else if (red == 64)
821 { 823 {
822 if (green == 64) 824 if (green == 64)
823 { 825 {
824 if (blue == 255) 826 if (blue == 255)
825 return 13; /* high intensity blue */ 827 return lookup_color(14, foreground) + 1; /* light blue */
826 } 828 }
827 else if (green == 255) 829 else if (green == 255)
828 { 830 {
829 if (blue == 64) 831 if (blue == 64)
830 return 11; /* high intensity green */ 832 return lookup_color(16, foreground) + 1; /* light green */
831 if (blue == 255) 833 if (blue == 255)
832 return 15; /* high intensity cyan */ 834 return lookup_color(18, foreground) + 1; /* light cyan */
833 } 835 }
834 } 836 }
835 if (t_colors >= 256) 837 if (t_colors >= 256)
836 { 838 {
837 if (red == blue && red == green) 839 if (red == blue && red == green)
900 return get_tgc_attr_idx(attr, fg, bg); 902 return get_tgc_attr_idx(attr, fg, bg);
901 } 903 }
902 else 904 else
903 #endif 905 #endif
904 { 906 {
905 return get_cterm_attr_idx(attr, color2index(&cell->fg), 907 return get_cterm_attr_idx(attr, color2index(&cell->fg, TRUE),
906 color2index(&cell->bg)); 908 color2index(&cell->bg, FALSE));
907 } 909 }
908 return 0; 910 return 0;
909 } 911 }
910 912
911 /* 913 /*