shithub: riscv

Download patch

ref: ecb12c87187a37a74f77aff45ffece9f7e985658
parent: 5d790e08ca051d74f2146014a4426bbc217680e8
author: Sigrid <[email protected]>
date: Sun Dec 6 06:55:27 EST 2020

aux/status^(bar msg): few small fixes (thanks umbraticus)

--- a/sys/man/8/statusbar
+++ b/sys/man/8/statusbar
@@ -9,8 +9,9 @@
 [
 .B -w
 .I minx,miny,maxx,maxy
-]
+] [
 .I title
+]
 .br
 .B aux/statusmsg
 [
--- a/sys/src/cmd/aux/statusbar.c
+++ b/sys/src/cmd/aux/statusbar.c
@@ -21,10 +21,10 @@
 	text = display->black;
 	light = allocimagemix(display, DPalegreen, DWhite);
 	dark = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkgreen);
+	if(light == nil || dark == nil) sysfatal("initcolor: %r");
 }
 
 Rectangle rbar;
-Point ptext;
 vlong n, d;
 int last;
 int lastp = -1;
@@ -75,7 +75,7 @@
 	if(lastp != p){
 		sprint(buf, "%3d%%", p);
 		
-		stringbg(screen, addpt(screen->r.min, Pt(Dx(rbar)-30, 4)), text, ZP, display->defaultfont, buf, light, ZP);
+		stringbg(screen, Pt(screen->r.max.x-4-stringwidth(display->defaultfont, buf), screen->r.min.y+4), text, ZP, display->defaultfont, buf, light, ZP);
 		lastp = p;
 	}
 
@@ -94,24 +94,13 @@
 void
 eresized(int new)
 {
-	Point p, q;
-	Rectangle r;
-
 	if(new && getwindow(display, Refnone) < 0)
 		fprint(2,"can't reattach to window");
 
-	r = screen->r;
-	draw(screen, r, light, nil, ZP);
-	p = string(screen, addpt(r.min, Pt(4,4)), text, ZP,
-		display->defaultfont, title);
-
-	p.x = r.min.x+4;
-	p.y += display->defaultfont->height+4;
-
-	q = subpt(r.max, Pt(4,4));
-	rbar = Rpt(p, q);
-
-	ptext = Pt(r.max.x-4-stringwidth(display->defaultfont, "100%"), r.min.x+4);
+	draw(screen, screen->r, light, nil, ZP);
+	if(title) string(screen, addpt(screen->r.min, Pt(4,4)), text, ZP, font, title);
+	rbar = insetrect(screen->r, 4);
+	rbar.min.y += font->height + 4;
 	border(screen, rbar, -2, dark, ZP);
 	last = 0;
 	lastp = -1;
@@ -163,7 +152,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: aux/statusbar [-kt] [-w minx,miny,maxx,maxy] 'title'\n");
+	fprint(2, "usage: %s [-kt] [-w minx,miny,maxx,maxy] [title]\n", argv0);
 	exits("usage");
 }
 
@@ -190,11 +179,14 @@
 		usage();
 	}ARGEND;
 
-	if(argc != 1)
+	switch(argc){
+	default:
 		usage();
-
-	title = argv[0];
-
+	case 1:
+		title = argv[0];
+	case 0:
+		break;
+	}
 	lfd = dup(0, -1);
 
 	while(q = strchr(p, ','))
@@ -204,7 +196,7 @@
 		textmode = 1;
 		rbar = Rect(0, 0, 60, 1);
 	}else{
-		if(initdraw(0, 0, title) < 0)
+		if(initdraw(0, 0, title ? title : argv0) < 0)
 			exits("initdraw");
 		initcolor();
 		einit(Emouse|Ekeyboard);
--- a/sys/src/cmd/aux/statusmsg.c
+++ b/sys/src/cmd/aux/statusmsg.c
@@ -22,6 +22,7 @@
 {
 	text = display->black;
 	light = allocimagemix(display, DPalegreen, DWhite);
+	if(light == nil) sysfatal("initcolor: %r");
 }
 
 void
@@ -136,7 +137,6 @@
 		usage();
 	case 1:
 		title = argv[0];
-		break;
 	case 0:
 		break;
 	}
@@ -153,7 +153,7 @@
 		if((bout = Bfdopen(1, OWRITE)) == nil)
 			sysfatal("Bfdopen: %r");
 	}else{
-		if(initdraw(0, 0, title) < 0)
+		if(initdraw(0, 0, title ? title : argv0) < 0)
 			sysfatal("initdraw: %r");
 		initcolor();
 		einit(Emouse|Ekeyboard);