summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-08-10 22:42:53 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-08-10 23:07:05 +0200
commit07f6d0b350c00c754450e0e00efb39e234e78c21 (patch)
tree1613bb248e17d3afc07fd7384c113d06e013b095
parent1cc8656368e229e9a63e8fdc8417451f2d955e49 (diff)
downloadxK-07f6d0b350c00c754450e0e00efb39e234e78c21.tar.gz
xK-07f6d0b350c00c754450e0e00efb39e234e78c21.tar.xz
xK-07f6d0b350c00c754450e0e00efb39e234e78c21.zip
degesch: enable bright backgrounds on 8-color terms
-rw-r--r--degesch.c29
1 files 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);