21 text = display->black;
22 light = allocimagemix(display, DPalegreen, DWhite);
23 dark = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkgreen);
24 if(light == nil || dark == nil) sysfatal("initcolor: %r");
39 char buf[400], bar[200];
40 static char lastbar[200];
42 if(n > d || n < 0 || d <= 0)
57 for(; j<Dx(rbar); j++)
61 sprint(bar+j, "%3d%% ", p);
62 for(i=0; bar[i]==lastbar[i] && bar[i]; i++)
64 memset(buf, '\b', strlen(lastbar)-i);
65 strcpy(buf+strlen(lastbar)-i, bar+i);
67 write(1, buf, strlen(buf));
72 if(lastp == p && last == i)
76 sprint(buf, "%3d%%", p);
78 stringbg(screen, Pt(screen->r.max.x-4-stringwidth(display->defaultfont, buf), screen->r.min.y+4), text, ZP, display->defaultfont, buf, light, ZP);
84 draw(screen, Rect(rbar.min.x+last, rbar.min.y, rbar.min.x+i, rbar.max.y),
87 draw(screen, Rect(rbar.min.x+i, rbar.min.y, rbar.min.x+last, rbar.max.y),
91 flushimage(display, 1);
97 if(new && getwindow(display, Refnone) < 0)
98 fprint(2,"can't reattach to window");
100 draw(screen, screen->r, light, nil, ZP);
101 if(title) string(screen, addpt(screen->r.min, Pt(4,4)), text, ZP, font, title);
102 rbar = insetrect(screen->r, 4);
103 rbar.min.y += font->height + 4;
104 border(screen, rbar, -2, dark, ZP);
116 int k, die, parent, child;
124 switch(child = rfork(RFMEM|RFPROC)) {
127 while(!die && (k = eread(Ekeyboard|Emouse, &e))) {
128 if(nokill==0 && k == Ekeyboard && (e.kbdc == Kdel || e.kbdc == Ketx)) {
130 postnote(PNPROC, parent, "interrupt");
137 while(!die && (p = Brdline(b, '\n'))) {
138 p[Blinelen(b)-1] = '\0';
139 if(tokenize(p, f, 2) != 2)
141 n = strtoll(f[0], 0, 0);
142 d = strtoll(f[1], 0, 0);
148 postnote(PNPROC, child, "kill");
155 fprint(2, "usage: %s [-kt] [-w minx,miny,maxx,maxy] [title]\n", argv0);
160 main(int argc, char **argv)
192 while(q = strchr(p, ','))
194 Binit(&b, lfd, OREAD);
195 if(textmode || newwin(p) < 0){
197 rbar = Rect(0, 0, 60, 1);
199 if(initdraw(0, 0, title ? title : argv0) < 0)
202 einit(Emouse|Ekeyboard);
217 snprint(spec, sizeof(spec), "-r %s", win);
220 if(newwindow(win) < 0){
221 fprint(2, "%s: newwindow: %r", argv0);
224 if((cons = open("/dev/cons", OREAD)) < 0){
226 fprint(2, "%s: can't open /dev/cons: %r", argv0);
231 if((cons = open("/dev/cons", OWRITE)) < 0)