shithub: orca

Download patch

ref: 7ff07a595fbe47cc37e64650ce4a6ab05c72f804
parent: 98ffa7f810093bbffc0ccb24bb38a6992bacfdb0
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 09:59:49 EST 2020

plan9: proper coloring

--- a/plan9.c
+++ b/plan9.c
@@ -305,6 +305,8 @@
 	Rectangle r;
 	Point p, top, bot;
 	int x, y, len, rx, ry;
+	int bg, fg, attr;
+	Rune c;
 
 	draw(screen, screen->r, color[Dback], nil, ZP);
 	p = screen->r.min;
@@ -314,22 +316,67 @@
 	bot.x = top.x;
 	bot.y = screen->r.max.y - Txtoff - charh*2;
 
+	/* cursor bg */
+	p.x += curx * charw;
+	p.y += cury * charh;
+	r.min = p;
+	r.max = p;
+	r.max.x += selw * charw;
+	r.max.y += selh * charh;
+	draw(screen, r, color[Dbinv], nil, ZP);
+
+	p = top;
+
 	for (y = 0; y < field.height && p.y < bot.y-charh; y++) {
 		for (x = 0; x < field.width; x++) {
-			Rune c = field.buffer[field.width*y + x];
-			if (c == '.') {
+			c = field.buffer[field.width*y + x];
+			attr = mbuf.buffer[field.width*y + x];
+
+			if (c == '.')
 				c = dot[dotstyle];
+
+			if (c == dot[dotstyle] && attr == 0) {
 				if ((x % gridw) == 0 && (y % gridh) == 0) {
 					rx = !!x + (x + 1) / field.width;
 					ry = !!y + (y + 1) / field.height;
 					c = ruler[rulerstyle][ry*3+rx];
 				}
+				runestringn(screen, p, color[Dflow], ZP, font, &c, 1);
+			} else if (x >= curx && y >= cury && x < curx+selw && y < cury+selh) {
+				runestringn(screen, p, color[Dfinv], ZP, font, &c, 1);
+			} else {
+				bg = Dback;
+				fg = Dfhigh;
+
+				if (c == '#') {
+					fg = Dfmed;
+				} else {
+					if (c >= 'A' && c <= 'Z') {
+						bg = Dbmed;
+						fg = Dfinv;
+					}
+					if (attr & Mark_flag_input) {
+						bg = Dback;
+						fg = Dfhigh;
+					} else if (attr & Mark_flag_lock) {
+						bg = Dback;
+						fg = Dfmed;
+					}
+				}
+
+				if (attr & Mark_flag_output) {
+					bg = Dfhigh;
+					fg = Dfinv;
+				} else if (attr & Mark_flag_haste_input) {
+					bg = Dback;
+					fg = Dbmed;
+				}
+				runestringnbg(screen, p, color[fg], ZP, font, &c, 1, color[bg], ZP);
 			}
-			linebuf[x] = c;
+			p.x += charw;
 		}
-		linebuf[x] = 0;
-		runestring(screen, p, color[Dflow], ZP, font, linebuf);
 		p.y += font->height;
+		p.x = top.x;
 	}
 
 	p = bot;
@@ -381,16 +428,6 @@
 	runestring(screen, p, color[Dfhigh], ZP, font, linebuf);
 
 	USED(len);
-
-	/* cursor bg */
-	p = top;
-	p.x += curx * charw;
-	p.y += cury * charh;
-	r.min = p;
-	r.max = p;
-	r.max.x += selw * charw;
-	r.max.y += selh * charh;
-	draw(screen, r, color[Dbinv], nil, ZP);
 
 	flushimage(display, 1);
 }