shithub: orca

Download patch

ref: 4bac4cbddf93e60475b5a51f8f28c2e1bb7ff207
parent: 54d976397b07916da9c97407423eff7cee67cc54
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Feb 13 08:45:25 EST 2020

plan9: better info drawing, handle ` to enter/leave sliding mode

--- a/plan9.c
+++ b/plan9.c
@@ -12,6 +12,7 @@
 
 enum {
 	Txtoff = 16,
+	Coloff = 2,
 	Msgredraw = 0,
 };
 
@@ -41,7 +42,7 @@
 static char filename[256];
 static Channel *cchan;
 static Field copyfield;
-static int altdown;
+static int altdown, slide;
 static long framedev; /* frame deviation >= 1µs */
 
 static char *menu3i[] = {
@@ -241,7 +242,7 @@
 
 	/* field size */
 	p.x = screen->r.min.x + Txtoff;
-	len = runesprint(linebuf, "%udx%ud", field.width, field.height);
+	len = MAX(3+1+3, runesprint(linebuf, "%udx%ud", field.width, field.height));
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* cursor position */
@@ -249,38 +250,44 @@
 	runesprint(linebuf, "%ud,%ud", curx, cury);
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
+	/* selection size */
+	p.x += charw * (len + Coloff);
+	len = MAX(2+1+2, runesprint(linebuf, "%d:%d", selw, selh));
+	runestring(screen, p, display->white, ZP, font, linebuf);
+
 	/* grid size */
 	p.y -= font->height;
-	p.x += charw * (len + 3);
-	len = runesprint(linebuf, "%d/%d", gridw, gridh);
+	runesprint(linebuf, "%d/%d", gridw, gridh);
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* ticks */
-	p.x += charw * (len + 3);
+	p.x += charw * (len + Coloff);
 	runesprint(linebuf, "%ludf", tick);
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* insert/append mode */
 	p.y += font->height;
-	len = runesprint(linebuf, "%s", altdown ? "slide " : (insert ? "insert" : "append"));
+	len = MAX(6, runesprint(linebuf, "%s", (altdown || slide) ? "slide" : (insert ? "insert" : "append")));
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* bpm */
 	p.y -= font->height;
-	p.x += charw * (len + 3);
-	len = runesprint(linebuf, "%d", bpm);
+	p.x += charw * (len + Coloff);
+	len = MAX(6, runesprint(linebuf, "%d", bpm));
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* filename */
 	p.y += font->height;
-	string(screen, p, display->white, ZP, font, filename);
+	string(screen, p, display->white, ZP, font, filename[0] ? filename : "unnamed");
 
 	/* frame deviation */
 	p.y -= font->height;
-	p.x += charw * (len + 3);
-	runesprint(linebuf, "%ldµs", labs(framedev));
+	p.x += charw * (len + Coloff);
+	len = MAX(6, runesprint(linebuf, "%ldµs", labs(framedev)));
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
+	USED(len);
+
 	/* cursor bg */
 	p = top;
 	p.x += curx * charw;
@@ -561,7 +568,7 @@
 				if (shiftdown)
 					selh = MAX(1, selh-1);
 				else {
-					if (altdown)
+					if (altdown || slide)
 						selmove(0, -1);
 					cury = MAX(0, cury-1);
 				}
@@ -571,7 +578,7 @@
 				if (shiftdown)
 					selh++;
 				else {
-					if (altdown)
+					if (altdown || slide)
 						selmove(0, 1);
 					cury = MIN(h-1, cury+1);
 				}
@@ -581,7 +588,7 @@
 				if (shiftdown)
 					selw = MAX(1, selw-1);
 				else {
-					if (altdown)
+					if (altdown || slide)
 						selmove(-1, 0);
 					curx = MAX(0, curx-1);
 				}
@@ -591,7 +598,7 @@
 				if (shiftdown)
 					selw++;
 				else {
-					if (altdown)
+					if (altdown || slide)
 						selmove(1, 0);
 					curx = MIN(w-1, curx+1);
 				}
@@ -635,11 +642,16 @@
 				insert = !insert;
 				break;
 			case Kesc:
-				if (!insert)
+				if (slide)
+					slide = 0;
+				else if (!insert)
 					insert = 1;
 				else
 					selw = selh = 1;
 				/* FIXME else remove selection */
+				break;
+			case '`':
+				slide = !slide;
 				break;
 			case ' ':
 				if (insert) {