degesch: enable bright backgrounds on 8-color terms

This commit is contained in:
Přemysl Eric Janouch 2015-08-10 22:42:53 +02:00
parent 1cc8656368
commit 07f6d0b350
1 changed files with 23 additions and 6 deletions

View File

@ -2227,19 +2227,36 @@ attribute_printer_update (struct attribute_printer *self)
int bg = attribute_printer_decode_color int bg = attribute_printer_decode_color
(self->want_background, &bg_is_bright); (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; int attributes = self->want;
if (attributes & ATTRIBUTE_INVERSE) bool have_inverse = !!(attributes & ATTRIBUTE_INVERSE);
if (have_inverse)
{ {
bool tmp = fg_is_bright; bool tmp = fg_is_bright;
fg_is_bright = bg_is_bright; fg_is_bright = bg_is_bright;
bg_is_bright = tmp; bg_is_bright = tmp;
} }
if (fg_is_bright) attributes |= ATTRIBUTE_BOLD; // In 8 colour mode, some terminals don't support bright backgrounds.
if (bg_is_bright) attributes |= ATTRIBUTE_BLINK; // 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); attribute_printer_reset (self);