mg icon indicating copy to clipboard operation
mg copied to clipboard

attempt to add basic syntax highlighting

Open CDitzel opened this issue 6 months ago • 0 comments

https://github.com/hboetes/mg/blob/32efa2519d61f1402e8c4d6998b1db0a4408e41e/display.c#L330

so I tried to implement a basic syntax highlighting by first trying to color in digits. I tried to utilize ANSI escape codes as follows

	} else if (isprint(c)){
	    if (isdigit(c)){
		char buf[5];
		int clen = snprintf(buf, sizeof(buf), "\x1b[35m");
		for(uint32_t i = 0; i < 5; ++i){
		    vp->v_text[vtcol++] = buf[i];
		} 
		vp->v_text[vtcol++] = c;
		clen = snprintf(buf, sizeof(buf), "\x1b[39m");
		for(uint32_t i = 0; i < 5; ++i){
		    vp->v_text[vtcol++] = buf[i];
		} 
	    }
	    else
		vp->v_text[vtcol++] = c;
	}

but this does not seem to work as it only hides the digits and shrinks the modeline.

Anyone any idea on how to proceed here? Uploading gh.png…

CDitzel avatar Aug 22 '24 18:08 CDitzel