From 07f6d0b350c00c754450e0e00efb39e234e78c21 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Mon, 10 Aug 2015 22:42:53 +0200
Subject: degesch: enable bright backgrounds on 8-color terms
---
degesch.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/degesch.c b/degesch.c
index 35dcce0..4914bc4 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2227,19 +2227,36 @@ attribute_printer_update (struct attribute_printer *self)
int bg = attribute_printer_decode_color
(self->want_background, &bg_is_bright);
- // TODO: (INVERSE | BOLD) should be used for bright backgrounds
- // when possible, i.e. when the foreground shouldn't be bright as well
- // and when the BOLD attribute hasn't already been set
int attributes = self->want;
- if (attributes & ATTRIBUTE_INVERSE)
+ bool have_inverse = !!(attributes & ATTRIBUTE_INVERSE);
+ if (have_inverse)
{
bool tmp = fg_is_bright;
fg_is_bright = bg_is_bright;
bg_is_bright = tmp;
}
- if (fg_is_bright) attributes |= ATTRIBUTE_BOLD;
- if (bg_is_bright) attributes |= ATTRIBUTE_BLINK;
+ // In 8 colour mode, some terminals don't support bright backgrounds.
+ // However, we can make use of the fact that the brightness change caused
+ // by the bold attribute is retained when inverting the colours.
+ // This has the downside of making the text bold when it's not supposed
+ // to be, and we still can't make both colours bright, so it's more of
+ // an interesting hack rather than anything else.
+ if (!fg_is_bright && bg_is_bright && have_inverse)
+ attributes |= ATTRIBUTE_BOLD;
+ else if (!fg_is_bright && bg_is_bright
+ && !have_inverse && fg >= 0 && bg >= 0)
+ {
+ // As long as none of the colours is the default, we can swap them
+ int tmp = fg; fg = bg; bg = tmp;
+ attributes |= ATTRIBUTE_BOLD | ATTRIBUTE_INVERSE;
+ }
+ else
+ {
+ // This is what works on normal, decent terminals
+ if (fg_is_bright) attributes |= ATTRIBUTE_BOLD;
+ if (bg_is_bright) attributes |= ATTRIBUTE_BLINK;
+ }
attribute_printer_reset (self);
--
cgit v1.2.3-70-g09d2