shithub: spit

Download patch

ref: 80ce5fd9ffcf039156695e5f8ed34f19a44c6d9c
parent: d07d0d70f9542cfc0064ca17be6dea6d05db145a
author: phil9 <telephil9@gmail.com>
date: Sun Feb 4 09:27:42 EST 2024

add barf mode (thanks qwx)

	when passing the -n flag, spit will switch to barf mode and
	render the presentation to images instead of rendering to screen.

--- a/spit.c
+++ b/spit.c
@@ -15,6 +15,7 @@
 int			curslide;
 Image		*bol;
 Image		*bullet;
+int			nodraw;
 
 void
 ladd(Lines *l, char *s)
@@ -283,6 +284,22 @@
 }
 
 void
+barf(void)
+{
+	int fd;
+	char path[64];
+	Image **i;
+
+	for(i=slides; i<slides+nslides+1; i++){
+		snprint(path, sizeof path, "spit.%03zd.bit", i - slides);
+		if((fd = create(path, OWRITE, 0644)) < 0)
+			sysfatal("open: %r");
+		writeimage(fd, *i, 0);
+		close(fd);
+	}
+}
+
+void
 redraw(void)
 {
 	draw(screen, screen->r, slides[curslide], nil, ZP);
@@ -364,7 +381,7 @@
 void
 usage(void)
 {
-	fprint(2, "%s [-f font] [-F fixedfont] <filename>\n", argv0);
+	fprint(2, "%s [-n] [-f font] [-F fixedfont]<filename>\n", argv0);
 	exits("usage");
 }
 
@@ -385,6 +402,9 @@
 	tname = nil;
 	fname = nil;
 	ARGBEGIN{
+	case 'n':
+		nodraw = 1;
+		break;
 	case 'f':
 		tname = EARGF(usage());
 		break;
@@ -419,6 +439,10 @@
 	initstyle(tname, fname);
 	initimages();
 	render(f);
+	if(nodraw){
+		barf();
+		threadexitsall(nil);
+	}
 	resize();
 	for(;;){
 		switch(alt(alts)){