ref: b7d24f43ad9d35aa4b485849a5b682222ae7618a
parent: 90aa80652f40e96daf6da2b2193c735979073b27
author: BurnZeZ <brz-9dev@feline.systems>
date: Fri May 5 17:43:30 EDT 2017
aux/statusmsg: use libbio for textmode output calling write(1, "\b", 1); for each rune to be removed is a lot of overhead, and we don’t want rio to turn each of these writes into a draw operation. also, it now prints to stderr before exiting if initdraw() fails
--- a/sys/src/cmd/aux/statusmsg.c
+++ b/sys/src/cmd/aux/statusmsg.c
@@ -10,7 +10,8 @@
int nokill;
int textmode;
char *title = nil;
-char message[1024];
+char *message = nil;
+Biobuf *bout;
Image *light;
Image *text;
@@ -30,8 +31,9 @@
static int last = 0;
while(last-- > 0)
- write(1, "\b", 1);
- write(1, message, strlen(message));
+ Bputc(bout, '\b');
+ Bwrite(bout, message, strlen(message));
+ Bflush(bout);
last = utflen(message);
return;
}
@@ -70,8 +72,9 @@
if(textmode){child = -1;
if(title){- write(1, title, strlen(title));
- write(1, ": ", 2);
+ Bwrite(bout, title, strlen(title));
+ Bwrite(bout, ": ", 2);
+ Bflush(bout);
}
} else
switch(child = rfork(RFMEM|RFPROC)) {@@ -86,12 +89,14 @@
}
_exits(0);
}
- while(!die && (p = Brdline(b, '\n'))) {- snprint(message, sizeof(message), "%.*s", Blinelen(b)-1, p);
+ while(!die && (p = Brdline(b, '\n'))){+ snprint(message, Bsize, "%.*s", Blinelen(b)-1, p);
drawmsg();
}
- if(textmode)
- write(1, "\n", 1);
+ if(textmode){+ Bwrite(bout, "\n", 1);
+ Bterm(bout);
+ }
postnote(PNPROC, child, "kill");
}
@@ -140,11 +145,16 @@
while(q = strchr(p, ','))
*q = ' ';
Binit(&b, lfd, OREAD);
+ if((message = malloc(Bsize)) == nil)
+ sysfatal("malloc: %r");+ memset(message, 0, Bsize);
if(textmode || newwin(p) < 0){textmode = 1;
+ if((bout = Bfdopen(1, OWRITE)) == nil)
+ sysfatal("Bfdopen: %r"); }else{if(initdraw(0, 0, title) < 0)
- exits("initdraw");+ sysfatal("initdraw: %r");initcolor();
einit(Emouse|Ekeyboard);
eresized(0);
--
⑨