shithub: spread

Download patch

ref: e508450a625b0841b0825387b57be011ab89e1c5
parent: f5d1631b91dd7a70c50b84912411465ad94ff2e6
author: sirjofri <sirjofri@sirjofri.de>
date: Thu Jul 4 11:35:22 EDT 2024

track dirty state, display file and dirty state

--- a/spread.c
+++ b/spread.c
@@ -78,8 +78,23 @@
 Drawstate dstate;
 Colors colors;
 Event ev;
+char *file = nil;
+int dirty = 0;
 
 void
+drawfile(void)
+{
+	char filebuf[25];
+	char *f;
+	
+	f = strrchr(file, '/');
+	f = f ? f+1 : file;
+	
+	snprint(filebuf, sizeof(filebuf), "%s%s", f, dirty ? "*" : "");
+	string(screen, addpt(screen->r.min, Pt(4, 4)), display->black, ZP, font, filebuf);
+}
+
+void
 redraw(void)
 {
 	P dim;
@@ -93,15 +108,17 @@
 	Response r;
 	char buf[10];
 	
+	draw(screen, screen->r, colors.bg, nil, ZP);
+	
+	drawfile();
+	
 	dstate.r = insetrect(screen->r, 4);
-	dstate.r.min.y += font->height;
+	dstate.r.min.y += font->height * 2;
 	dstate.r.min.x += stringwidth(font, "88888888");
 	dx = Dx(dstate.r);
 	dy = Dy(dstate.r);
 	
 	first = dstate.firstcell;
-	
-	draw(screen, screen->r, colors.bg, nil, ZP);
 	dim = getcelldim(&dstate);
 	
 	for (x = first.x; x < first.x + dim.x; x++) {
@@ -187,6 +204,7 @@
 	
 	addcell(p, s, type);
 	updatecells();
+	dirty = 1;
 	redraw();
 }
 
@@ -220,7 +238,6 @@
 	set(p, buf);
 }
 
-char *file = nil;
 int interactive = 0;
 
 static void
@@ -271,10 +288,13 @@
 	case 'w': /* write command */
 		if (n == 1) {
 			writefile(file);
+			dirty = 0;
 			break;
 		}
 		if (n == 2) {
-			writefile(args[1]);
+			file = strdup(args[1]);
+			writefile(file);
+			dirty = 0;
 			break;
 		}
 		/* TODO: error, bad command */
@@ -331,8 +351,6 @@
 			processcmd(cmd);
 	}
 	
-	return 0;
-
 Movement:
 	redraw();