ref: 59e8bc0e233e92a3bfd195f51b83fe54daa7ed93
parent: 74b6d9bda30b112c7d51bee2f549385de43bb930
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);