shithub: mez

Download patch

ref: b55a9366dc1009f5d98fe4c0a937758afd87bc4b
parent: 1be7f16d6216762401da82b50a1b1606f5ac9667
author: spew <spew@palas>
date: Fri Jan 31 19:18:38 EST 2025

Draw the nicks to the other screen

--- a/guitest.c
+++ b/guitest.c
@@ -18,6 +18,9 @@
 	MOUSE,
 	KEYBD,
 	RESIZE,
+	MOUSENICK,
+	KEYBDNICK,
+	RESIZENICK,
 	NCHAN,
 
 	Scrollwid = 12,		/* width of scroll bar */
@@ -83,7 +86,7 @@
 		scrpos.max.y = scrpos.min.y+Dy(t->scrollr)*t->Frame.maxlines/t->nlines;
 	}
 	scrpos = insetrect(scrpos, 1);
-	draw(screen, scrpos, t->cols[BACK], nil, ZP);
+	draw(t->screen, scrpos, t->cols[BACK], nil, ZP);
 
 	frinsert(t, t->text + t->lines[t->topline], t->text + t->textlen, 0);
 	flushimage(display, 1);
@@ -99,14 +102,18 @@
 	t->bodyr.min.y = t->screen->r.min.y;
 	t->bodyr.max = t->screen->r.max;
 
-	t->text = emallocz(8192*sizeof(*t->text), 1);
-	t->textcap = 8192;
-	t->textlen = 0;
+	if(t->text == nil){
+		t->textcap = 8192;
+		t->text = emallocz(t->textcap*sizeof(*t->text), 1);
+		t->textlen = 0;
+	}
 
-	t->linescap = 1024;
-	t->lines = emallocz(t->linescap*sizeof(*t->lines), 1);
-	t->nlines = 0;
-	t->topline = 0;
+	if(t->lines == nil){
+		t->linescap = 1024;
+		t->lines = emallocz(t->linescap*sizeof(*t->lines), 1);
+		t->nlines = 0;
+		t->topline = 0;
+	}
 
 	frclear(t, 0);
 	frinit(t, t->bodyr, display->defaultfont, t->screen, t->cols);
@@ -130,7 +137,7 @@
 	int len;
 
 	len = runestrlen(s);
-	while(len-1 > t->textcap-t->textlen){
+	while(len > t->textcap-t->textlen+1){
 		t->textcap *= 2;
 		t->text = erealloc(t->text, t->textcap*sizeof(*t->text));
 	}
@@ -184,6 +191,13 @@
 	textinit(&chan->body);
 	textaddlines(&chan->body, lorem);
 
+
+	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((wsys = getenv("wsys")) == nil)
 		sysfatal("cannot find $wsys: %r");
 	if((fd = open(wsys, ORDWR)) < 0)
@@ -193,6 +207,13 @@
 		sysfatal("cannot create new window: %r");
 	if(gengetwindow(display, "/mnt/wsysnicks/winname", &chan->nicks.screen, &chan->nicks._screen, Refnone) < 0)
 		sysfatal("cannot get window: %r");
+	chan->nicks.cols[BACK] = allocimagemix(display, DCyan, DWhite);
+	chan->nicks.cols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
+	chan->nicks.cols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue);
+	chan->nicks.cols[TEXT] = display->black;
+	chan->nicks.cols[HTEXT] = display->black;
+	textinit(&chan->nicks);
+	textaddlines(&chan->nicks, lorem);
 
 	Alt a[NCHAN+1] = {
 		[MOUSE] = {mc->c, &m, CHANRCV},
@@ -201,7 +222,7 @@
 		[NCHAN] = {nil, nil, CHANEND},
 	};
 	textdraw(&chan->body);
-	draw(chan->nicks.screen, chan->nicks.screen->r, chan->body.cols[HIGH], nil, ZP);
+	textdraw(&chan->nicks);
 	flushimage(display, 1);
 	for(;;)switch(alt(a)){
 	default: