Hello,

this has been bugging me for a while now, given the confusing logic at
the beginning of xdraws() didn't really invite going on.
This patch removes 13 lines and additionally makes the code much easier
to read.

Cheers

FRIGN

-- 
FRIGN <[email protected]>
>From b049b39a8834f91c751ac9a5c196bd01d9bbbb3c Mon Sep 17 00:00:00 2001
From: FRIGN <[email protected]>
Date: Sat, 7 Jun 2014 17:16:27 +0200
Subject: [PATCH] Refactor xdraws()

Simplify the logic and unify the brightening of colors for bold text
by increasing base.fg instead of directly setting fg.
This allows putting the bold-logic above the truecolor-checks, which
automatically fall back to desired behaviour.
---
 st.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)

diff --git a/st.c b/st.c
index 3681776..ba0bf72 100644
--- a/st.c
+++ b/st.c
@@ -3117,13 +3117,17 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 	if(base.mode & ATTR_ITALIC) {
 		if(base.fg == defaultfg)
 			base.fg = defaultitalic;
-		font = &dc.ifont;
-		frcflags = FRC_ITALIC;
-	} else if((base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD)) {
-		if(base.fg == defaultfg)
-			base.fg = defaultitalic;
-		font = &dc.ibfont;
-		frcflags = FRC_ITALICBOLD;
+		font = (base.mode & ATTR_BOLD)? &dc.ibfont : &dc.ifont;
+		frcflags = (base.mode & ATTR_BOLD)? FRC_ITALICBOLD : FRC_ITALIC;
+	} else if(base.mode & ATTR_BOLD) {
+		/*
+		 * change basic system colors [0-7]
+		 * to bright system colors [8-15]
+		 */
+		if(BETWEEN(base.fg, 0, 7))
+			base.fg += 8;
+		font = &dc.bfont;
+		frcflags = FRC_BOLD;
 	} else if(base.mode & ATTR_UNDERLINE) {
 		if(base.fg == defaultfg)
 			base.fg = defaultunderline;
@@ -3151,23 +3155,6 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 		bg = &dc.col[base.bg];
 	}
 
-	if(base.mode & ATTR_BOLD) {
-		/*
-		 * change basic system colors [0-7]
-		 * to bright system colors [8-15]
-		 */
-		if(BETWEEN(base.fg, 0, 7))
-			fg = &dc.col[base.fg + 8];
-
-		if(base.mode & ATTR_ITALIC) {
-			font = &dc.ibfont;
-			frcflags = FRC_ITALICBOLD;
-		} else {
-			font = &dc.bfont;
-			frcflags = FRC_BOLD;
-		}
-	}
-
 	if(IS_SET(MODE_REVERSE)) {
 		if(fg == &dc.col[defaultfg]) {
 			fg = &dc.col[defaultbg];
-- 
1.8.5.5

Reply via email to