ref: 1bfa8e43df6e6b3d160c6f0308dd3cf617aea536
parent: ccb2fe62a80e247e5cb6ae83addab916ec0d9696
author: spew <spew@palas>
date: Mon Feb 3 02:23:55 EST 2025
make the command window
--- a/guitest.c
+++ b/guitest.c
@@ -217,15 +217,24 @@
void
threadmain(int argc, char **argv)
{
+ Chan *chan;
Keyboardctl *kc, *nickskc;
+ Mouse m;
Mousectl *mc, *nicksmc;
Rune r, *rs;
- Mouse m;
- Chan *chan;
- char *s;
- int len;
+ Rectangle dim;
+ Text *cmd;
+ char *s, *nicksf;
+ int len, fd;
- ARGBEGIN{}ARGEND
+ nicksf = nil;
+ ARGBEGIN{
+ default:
+ sysfatal("foo");
+ case 'n':
+ nicksf = EARGF(sysfatal("foo"));
+ break;
+ }ARGEND
len = readn(0, buf, sizeof(buf));
buf[len] = '\0';
@@ -260,14 +269,24 @@
chan->body.wsys = "/dev";
textinit(&chan->body);
textaddlines(&chan->body, lorem);
+ lorem[0] = L'\0';
- len = readn(3, buf, sizeof(buf));
- buf[len] = '\0';
- for(s = buf, rs = lorem; *s != '\0'; s+=len, rs++)
- len = chartorune(rs, s);
- *rs = L'\0';
+ if(nicksf != nil){
+ if((fd = open(nicksf, OREAD)) < 0)
+ sysfatal("Could not open nicks file");
+ len = readn(fd, buf, sizeof(buf));
+ close(fd);
+ buf[len] = '\0';
+ for(s = buf, rs = lorem; *s != '\0'; s+=len, rs++)
+ len = chartorune(rs, s);
+ *rs = L'\0';
+ }
- createwindow(nickswsys, &nicksscreen, &_nicksscreen, (Rectangle){(Point){screen->r.min.x - Dx(screen->r)/3, screen->r.min.y-4}, (Point){screen->r.min.x-4, screen->r.max.y+4}});
+ dim = (Rectangle){
+ (Point){screen->r.min.x - Dx(screen->r)/3, screen->r.min.y-4},
+ (Point){screen->r.min.x-4, screen->r.max.y+4}
+ };
+ createwindow(nickswsys, &nicksscreen, &_nicksscreen, dim);
memmove(chan->nicks.cols, nickscols, sizeof(nickscols));
chan->nicks.screen = &nicksscreen;
@@ -276,8 +295,21 @@
textinit(&chan->nicks);
textaddlines(&chan->nicks, lorem);
+ cmd = emallocz(sizeof(*cmd), 1);
+ dim = (Rectangle){
+ (Point){screen->r.min.x - Dx(screen->r)/3, screen->r.min.y-Dy(screen->r)/4},
+ (Point){screen->r.max.x+4, screen->r.min.y-4}
+ };
+ createwindow(cmdwsys, &cmdscreen, &_cmdscreen, dim);
+ memmove(cmd->cols, cmdcols, sizeof(cmdcols));
+ cmd->screen = &cmdscreen;
+ cmd->_screen = &_cmdscreen;
+ cmd->wsys = cmdwsys;
+ textinit(cmd);
+
textdraw(&chan->body);
textdraw(&chan->nicks);
+ textdraw(cmd);
flushimage(display, 1);
initmousekbd("/dev", screen, &mc, &kc);
@@ -284,13 +316,13 @@
initmousekbd(nickswsys, nicksscreen, &nicksmc, &nickskc);
Alt a[NCHAN+1] = {
- [MOUSE] = {mc->c, &m, CHANRCV},
- [MOUSENICKS] = {nicksmc->c, &m, CHANRCV},
- [RESIZE] = {mc->resizec, nil, CHANRCV},
- [RESIZENICKS] = {nicksmc->resizec, nil, CHANRCV},
- [KEYBD] = {kc->c, &r, CHANRCV},
- [KEYBDNICKS] = {nickskc->c, &r, CHANRCV},
- [NCHAN] = {nil, nil, CHANEND},
+ [MOUSE] {mc->c, &m, CHANRCV},
+ [MOUSENICKS] {nicksmc->c, &m, CHANRCV},
+ [RESIZE] {mc->resizec, nil, CHANRCV},
+ [RESIZENICKS] {nicksmc->resizec, nil, CHANRCV},
+ [KEYBD] {kc->c, &r, CHANRCV},
+ [KEYBDNICKS] {nickskc->c, &r, CHANRCV},
+ [NCHAN] {nil, nil, CHANEND},
};
for(;;)switch(alt(a)){
default:
@@ -329,5 +361,6 @@
}
end:
unmount(nil, nickswsys);
+ unmount(nil, cmdwsys);
threadexitsall(0);
}