shithub: vexed

Download patch

ref: 455d3aef23a93d2289f6d0ecd3fd211e0cced138
parent: eeeeafb213a7ab5294a12fbc5884b3fe26198b2b
author: phil9 <[email protected]>
date: Sun Feb 18 10:25:43 EST 2024

add -d flag to dim the color of nul bytes.

--- a/cols.c
+++ b/cols.c
@@ -14,6 +14,7 @@
 		cols[HEX]    = display->white;
 		cols[ASCII]  = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
 		cols[HHEX]	 = display->black;
+		cols[DHEX]	 = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xAAAAAAFF^reverse);
 		cols[HIGH]	 = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
 		cols[SCROLL] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x999999FF^reverse);
 	}else{
@@ -22,6 +23,7 @@
 		cols[HEX]    = display->black;
 		cols[ASCII]  = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DGreygreen);
 		cols[HHEX]	 = display->black;
+		cols[DHEX]	 = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xAAAAAAFF);
 		cols[HIGH]   = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCFF);
 		cols[SCROLL] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x999999FF);
 	}
--- a/vexed.c
+++ b/vexed.c
@@ -81,6 +81,7 @@
 int nsbuf;
 char  sstr[256] = {0};
 int sindex = -1;
+int dimnul;
 
 int
 hexval(Rune k)
@@ -386,6 +387,7 @@
 	char b[8] = {0}, *s;
 	Point p;
 	Point p2;
+	Image *c;
 	
 	y = viewr.min.y + line * font->height;
 	index = (line + offset)*16;
@@ -412,7 +414,8 @@
 			p = stringnbg(screen, p, cols[HHEX], ZP, font, b, n, cols[HIGH], ZP);
 			p2 = stringnbg(screen, p2, cols[BACK], ZP, font, s, 1, cols[ASCII], ZP);
 		}else{
-			p = stringn(screen, p, cols[HEX], ZP, font, b, n);
+			c = dimnul && buf.data[index+i] == 0 ? cols[DHEX] : cols[HEX];
+			p = stringn(screen, p, c, ZP, font, b, n);
 			p2 = stringn(screen, p2, cols[ASCII], ZP, font, s, 1);
 		}
 		hs = 0;
@@ -821,9 +824,13 @@
 	scrolling = 0;
 	lastbuttons = 0;
 	reverse = 0;
+	dimnul = 0;
 	ARGBEGIN{
 	case 'b':
 		reverse = ~0xFF;
+		break;
+	case 'd':
+		dimnul = 1;
 		break;
 	default:
 		usage();