diff options
Diffstat (limited to 'src/ui/color.c')
-rw-r--r-- | src/ui/color.c | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/src/ui/color.c b/src/ui/color.c index 0f7d4368..adbe444b 100644 --- a/src/ui/color.c +++ b/src/ui/color.c | |||
@@ -785,8 +785,14 @@ static const iColor ansi8BitColors_[256] = { | |||
785 | { 255, 255, 255, 255 } | 785 | { 255, 255, 255, 255 } |
786 | }; | 786 | }; |
787 | 787 | ||
788 | iColor ansiForeground_Color(iRangecc escapeSequence, int fallback) { | 788 | void ansiColors_Color(iRangecc escapeSequence, int fgDefault, int bgDefault, |
789 | iColor clr = get_Color(fallback); | 789 | iColor *fg_out, iColor *bg_out) { |
790 | if (!fg_out && !bg_out) { | ||
791 | return; | ||
792 | } | ||
793 | iColor fg, bg; | ||
794 | iZap(fg); | ||
795 | iZap(bg); | ||
790 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { | 796 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { |
791 | char *endPtr; | 797 | char *endPtr; |
792 | unsigned long arg = strtoul(ch, &endPtr, 10); | 798 | unsigned long arg = strtoul(ch, &endPtr, 10); |
@@ -802,19 +808,37 @@ iColor ansiForeground_Color(iRangecc escapeSequence, int fallback) { | |||
802 | case 35: | 808 | case 35: |
803 | case 36: | 809 | case 36: |
804 | case 37: | 810 | case 37: |
805 | clr = ansi8BitColors_[arg - 30]; | 811 | fg = ansi8BitColors_[arg - 30]; |
806 | break; | 812 | break; |
807 | case 38: { | 813 | case 38: |
814 | case 48: { | ||
815 | iColor *dst = (arg == 38 ? &fg : &bg); | ||
808 | /* Extended foreground color. */ | 816 | /* Extended foreground color. */ |
809 | arg = strtoul(ch + 1, &endPtr, 10); | 817 | arg = strtoul(ch + 1, &endPtr, 10); |
810 | ch = endPtr; | 818 | ch = endPtr; |
811 | if (arg == 5) /* 8-bit palette */ { | 819 | if (arg == 5) /* 8-bit palette */ { |
812 | arg = strtoul(ch + 1, &endPtr, 10); | 820 | arg = strtoul(ch + 1, &endPtr, 10); |
813 | ch = endPtr; | 821 | ch = endPtr; |
814 | clr = ansi8BitColors_[iClamp(arg, 0, 255)]; | 822 | *dst = ansi8BitColors_[iClamp(arg, 0, 255)]; |
815 | } | 823 | } |
816 | break; | 824 | break; |
817 | } | 825 | } |
826 | case 39: | ||
827 | fg = get_Color(fgDefault); | ||
828 | break; | ||
829 | case 40: | ||
830 | case 41: | ||
831 | case 42: | ||
832 | case 43: | ||
833 | case 44: | ||
834 | case 45: | ||
835 | case 46: | ||
836 | case 47: | ||
837 | bg = ansi8BitColors_[arg - 40]; | ||
838 | break; | ||
839 | case 49: | ||
840 | bg = get_Color(bgDefault); | ||
841 | break; | ||
818 | case 90: | 842 | case 90: |
819 | case 91: | 843 | case 91: |
820 | case 92: | 844 | case 92: |
@@ -823,17 +847,36 @@ iColor ansiForeground_Color(iRangecc escapeSequence, int fallback) { | |||
823 | case 95: | 847 | case 95: |
824 | case 96: | 848 | case 96: |
825 | case 97: | 849 | case 97: |
826 | clr = ansi8BitColors_[8 + arg - 90]; | 850 | fg = ansi8BitColors_[8 + arg - 90]; |
827 | break; | 851 | break; |
828 | } | 852 | } |
829 | } | 853 | } |
830 | /* On light backgrounds, darken the colors to make them more legible. */ | 854 | /* Ensure legibility if only one of the colors is set. */ |
831 | if (get_HSLColor(tmBackground_ColorId).lum > 0.5f) { | 855 | /* TODO: Force darkening of the background color, unless it is also specified. */ |
832 | clr.r /= 2; | 856 | #if 0 |
833 | clr.g /= 2; | 857 | if (bg.a == 0 && !equal_Color(fg, get_Color(fgDefault))) { |
834 | clr.b /= 2; | 858 | if (delta_Color(fg, get_Color(tmBackground_ColorId)) < 64) { |
859 | const iHSLColor fgHsl = hsl_Color(fg); | ||
860 | iHSLColor legibleBg = get_HSLColor(tmBackground_ColorId); | ||
861 | if () | ||
862 | bg = rgb_HSLColor(bgHsl); | ||
863 | } | ||
864 | } | ||
865 | } | ||
866 | #endif | ||
867 | /* | ||
868 | if (!bg_out || get_HSLColor(tmBackground_ColorId).lum > 0.5f) { | ||
869 | fg.r /= 2; | ||
870 | fg.g /= 2; | ||
871 | fg.b /= 2; | ||
872 | } | ||
873 | */ | ||
874 | if (fg.a && fg_out) { | ||
875 | *fg_out = fg; | ||
876 | } | ||
877 | if (bg.a && bg_out) { | ||
878 | *bg_out = bg; | ||
835 | } | 879 | } |
836 | return clr; | ||
837 | } | 880 | } |
838 | 881 | ||
839 | iBool loadPalette_Color(const char *path) { | 882 | iBool loadPalette_Color(const char *path) { |