diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-01 22:00:11 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-01 22:00:11 +0200 |
commit | f5192df9720e046fc55b2f4f632709ba1e53f17b (patch) | |
tree | 511282726c1478c4885dfa612ae7e40efbfa110f | |
parent | 75a409c47a48f684c117f56122f84a3d8358f0b3 (diff) |
Fixed ANSI color handling issues
Added the missing BG escapes 100-107, and fixed how the FG is adjusted to keep text legible. Previously it was not considering the actual BG color being applied to a text run.
-rw-r--r-- | res/about/version.gmi | 4 | ||||
-rw-r--r-- | src/ui/color.c | 27 | ||||
-rw-r--r-- | src/ui/text.c | 19 |
3 files changed, 33 insertions, 17 deletions
diff --git a/res/about/version.gmi b/res/about/version.gmi index 63c026ac..438ff950 100644 --- a/res/about/version.gmi +++ b/res/about/version.gmi | |||
@@ -6,6 +6,10 @@ | |||
6 | ``` | 6 | ``` |
7 | # Release notes | 7 | # Release notes |
8 | 8 | ||
9 | ## 1.10.4 | ||
10 | * Added missing ANSI background color codes 100-107 (high-intensity VGA). | ||
11 | * Fixed how the ANSI FG color is adjusted to keep text legible on bright backgrounds when BG color is unset. | ||
12 | |||
9 | ## 1.10.3 | 13 | ## 1.10.3 |
10 | * Unix: Added a lagrange(1) manual page. | 14 | * Unix: Added a lagrange(1) manual page. |
11 | * Hide the [+] button on the tab button row if the navbar has a New Tab button. | 15 | * Hide the [+] button on the tab button row if the navbar has a New Tab button. |
diff --git a/src/ui/color.c b/src/ui/color.c index 3c2f0339..824342ae 100644 --- a/src/ui/color.c +++ b/src/ui/color.c | |||
@@ -868,23 +868,16 @@ void ansiColors_Color(iRangecc escapeSequence, int fgDefault, int bgDefault, | |||
868 | case 97: | 868 | case 97: |
869 | fg = ansi8BitColors_[8 + arg - 90]; | 869 | fg = ansi8BitColors_[8 + arg - 90]; |
870 | break; | 870 | break; |
871 | } | 871 | case 100: |
872 | } | 872 | case 101: |
873 | /* Ensure legibility if only the foreground color is set. */ | 873 | case 102: |
874 | if (fg.a) { | 874 | case 103: |
875 | const iHSLColor themeBg = get_HSLColor(tmBackground_ColorId); | 875 | case 104: |
876 | const float bgLuminance = luma_Color(get_Color(tmBackground_ColorId)); | 876 | case 105: |
877 | if (bgLuminance > 0.4f) { | 877 | case 106: |
878 | float dim = (bgLuminance - 0.4f); | 878 | case 107: |
879 | fg.r *= 0.5f * dim; | 879 | bg = ansi8BitColors_[8 + arg - 100]; |
880 | fg.g *= 0.5f * dim; | 880 | break; |
881 | fg.b *= 0.5f * dim; | ||
882 | } | ||
883 | if (themeBg.sat > 0.15f && themeBg.lum >= 0.5f) { | ||
884 | iHSLColor fgHsl = hsl_Color(fg); | ||
885 | fgHsl.hue = themeBg.hue; | ||
886 | fgHsl.lum = themeBg.lum * 0.5f; | ||
887 | fg = rgb_HSLColor(fgHsl); | ||
888 | } | 881 | } |
889 | } | 882 | } |
890 | if (fg.a && fg_out) { | 883 | if (fg.a && fg_out) { |
diff --git a/src/ui/text.c b/src/ui/text.c index 66231348..3fe56b59 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -697,6 +697,25 @@ struct Impl_AttributedRun { | |||
697 | 697 | ||
698 | static iColor fgColor_AttributedRun_(const iAttributedRun *d) { | 698 | static iColor fgColor_AttributedRun_(const iAttributedRun *d) { |
699 | if (d->fgColor_.a) { | 699 | if (d->fgColor_.a) { |
700 | /* Ensure legibility if only the foreground color is set. */ | ||
701 | if (!d->bgColor_.a) { | ||
702 | iColor fg = d->fgColor_; | ||
703 | const iHSLColor themeBg = get_HSLColor(tmBackground_ColorId); | ||
704 | const float bgLuminance = luma_Color(get_Color(tmBackground_ColorId)); | ||
705 | if (bgLuminance > 0.4f) { | ||
706 | float dim = (bgLuminance - 0.4f); | ||
707 | fg.r *= 0.5f * dim; | ||
708 | fg.g *= 0.5f * dim; | ||
709 | fg.b *= 0.5f * dim; | ||
710 | } | ||
711 | if (themeBg.sat > 0.15f && themeBg.lum >= 0.5f) { | ||
712 | iHSLColor fgHsl = hsl_Color(fg); | ||
713 | fgHsl.hue = themeBg.hue; | ||
714 | fgHsl.lum = themeBg.lum * 0.5f; | ||
715 | fg = rgb_HSLColor(fgHsl); | ||
716 | } | ||
717 | return fg; | ||
718 | } | ||
700 | return d->fgColor_; | 719 | return d->fgColor_; |
701 | } | 720 | } |
702 | if (d->attrib.fgColorId == none_ColorId) { | 721 | if (d->attrib.fgColorId == none_ColorId) { |