shithub: olednews

Download patch

ref: 13c0aeb1e423687204de24be782b9d1e2b1bb414
parent: afaf736459044632e33771effd9d8fc2d55689f3
author: glenda <glenda@narshaddaa>
date: Mon Apr 24 00:45:31 EDT 2023

good and fast text scrolling

--- a/textimg.c
+++ b/textimg.c
@@ -23,7 +23,7 @@
 		chanstr, m->r.min.x, m->r.min.y, m->r.max.x, m->r.max.y);
 
 	bpl = bytesperline(m->r, m->depth);
-	buf = malloc(bpl);
+	buf = malloc(bpl+1);
 	if(buf == nil)
 		sysfatal("malloc failed: %r");
 	for(y=m->r.min.y; y<m->r.max.y; y++){
@@ -43,7 +43,6 @@
 	char *s;
 	Memsubfont *f;
 	Point p;
-	Memimage *img;
 	char *path;
 	int fd;
 	Biobufhdr *in;
@@ -84,20 +83,21 @@
 	int h = 32;
 	int w = 126;
 	int y = 0;
-	int ms = 500;
+	int i;
+	int ms = 100;
 	long n;
 	ncharspline = w / p.x;
 	nlines = 2;	// i guess?
 	char *buf;
+	buf = calloc(ncharspline, sizeof (char));
 	fprint(2, "ncharspline: %d\n", ncharspline);
+	n = Bread(in, buf, ncharspline-1);
+	if(n <= 0)
+		sysfatal("no bread in the bread box");
+	buf[n] = '\0';
 
 	for(;;){
-		buf = calloc(ncharspline, sizeof (char));
-		n = Bread(in, buf, ncharspline-1);
-		if(n <= 0)
-			break;
-		buf[n] = '\0';
-
+		Memimage *img;
 		fprint(2, "buf str: %s\n", buf);
 
 		fd = open(path, OWRITE);
@@ -106,7 +106,7 @@
 		}
 		
 		//img = allocmemimage(Rect(0, 0, p.x, f->height), RGB24);
-		img = allocmemimage(Rect(0, 0, p.x*ncharspline, f->height), RGB24);
+		img = allocmemimage(Rect(0, 0, p.x*ncharspline, f->height), GREY1);
 		if (!img)
 			sysfatal("cannot allocate memimage: %r");
 		memfillcolor(img, DWhite);
@@ -115,12 +115,26 @@
 		writeuncompressed(fd, img);
 	
 		close(fd);
-		free(buf);
+		//free(buf);
 		if(y == 0)
 			y = h/2;
 		else
 			y = 0;
 
+		char c;
+		GETC:
+			c = Bgetc(in);
+			if(c <= 0)
+				break;
+			if(c == '\n' || c == '\r')
+				c = ' ';
+
+		for(i = 0; i < n-1; i++)
+			buf[i] = buf[i+1];
+		buf[n-1] = c;
+		//freememimage(img);
+
 		sleep(ms);
 	}
+	free(buf);
 }