degesch: enable bright backgrounds on 8-color terms
This commit is contained in:
		
							
								
								
									
										29
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user