diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-04-22 22:19:17 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-04-22 22:19:17 +0200 |
commit | 13a74150acae35fef6f9a07900c902335a810660 (patch) | |
tree | a7d7ab81a58dc99922bfba525a65a39f6ffba0b9 /sys/src/cmd/vt/main.c | |
parent | c029a0c9130b7a9b5a9c3883e813dd8d8a0a770d (diff) |
vt: handle nocolor flag and reversed background colors
Diffstat (limited to 'sys/src/cmd/vt/main.c')
-rw-r--r-- | sys/src/cmd/vt/main.c | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/sys/src/cmd/vt/main.c b/sys/src/cmd/vt/main.c index 467356069..e1658c083 100644 --- a/sys/src/cmd/vt/main.c +++ b/sys/src/cmd/vt/main.c @@ -47,6 +47,11 @@ Rune hist[HISTSIZ]; Rune *onscreenrbuf; uchar *onscreenabuf; uchar *onscreencbuf; + +#define onscreenr(x, y) &onscreenrbuf[((y)*(xmax+2) + (x))] +#define onscreena(x, y) &onscreenabuf[((y)*(xmax+2) + (x))] +#define onscreenc(x, y) &onscreencbuf[((y)*(xmax+2) + (x))] + int yscrmin, yscrmax; int attr, defattr; @@ -300,18 +305,40 @@ initialize(int argc, char **argv) } } -#define onscreenr(x, y) &onscreenrbuf[((y)*(xmax+2) + (x))] -#define onscreena(x, y) &onscreenabuf[((y)*(xmax+2) + (x))] -#define onscreenc(x, y) &onscreencbuf[((y)*(xmax+2) + (x))] +Image* +bgcol(int a, int c) +{ + if(nocolor || (c & (1<<0)) == 0){ + if(a & TReverse) + return fgcolor; + return bgcolor; + } + if((a & TReverse) != 0) + c >>= 4; + return colors[(c>>1)&7]; +} -#define bgcol(a, c) (((a)&TReverse)!=0 ? (c)>>4 : (c&15)) -#define fgcol(a, c) ((((a)&TReverse)==0 ? (c)>>4 : (c&15)) | (((a)&THighIntensity)!=0)<<4) +Image* +fgcol(int a, int c) +{ + if(nocolor || (c & (1<<4)) == 0){ + if(a & TReverse) + return bgcolor; + return fgcolor; + } + if((a & TReverse) == 0) + c >>= 4; + if(a & THighIntensity) + return hicolors[(c>>1)&7]; + return colors[(c>>1)&7]; +} void drawscreen(void) { int x, y, n; - uchar c, *ap, *cp; + uchar *ap, *cp; + Image *c; Rune *rp; draw(screen, screen->r, bgcolor, nil, ZP); @@ -320,15 +347,15 @@ drawscreen(void) for(y = 0; y <= ymax; y++){ for(x = 0; x <= xmax; x += n){ cp = onscreenc(x, y); - if((*cp & 1) == 0){ + ap = onscreena(x, y); + c = bgcol(*ap, *cp); + if(c == bgcolor){ n = 1; continue; } - ap = onscreena(x, y); - c = bgcol(*ap, *cp); for(n = 1; x+n <= xmax && bgcol(ap[n], cp[n]) == c; n++) ; - draw(screen, Rpt(pt(x, y), pt(x+n, y+1)), colors[c>>1], nil, ZP); + draw(screen, Rpt(pt(x, y), pt(x+n, y+1)), c, nil, ZP); } } @@ -345,9 +372,7 @@ drawscreen(void) c = fgcol(*ap, *cp); for(n = 1; x+n <= xmax && rp[n] != 0 && fgcol(ap[n], cp[n]) == c; n++) ; - runestringn(screen, pt(x, y), - (c&1) ? (((c&16) ? hicolors : colors)[(c&15)>>1]) : fgcolor, - ZP, font, rp, n); + runestringn(screen, pt(x, y), c, ZP, font, rp, n); } if(*onscreenr(x, y) == 0) runestringn(screen, pt(x, y), |