shithub: orca

Download patch

ref: f52fdefdd623584d40800f8e300276accf3ee876
parent: f2f73e37b78000a2a8e3f33a301e82f60b801284
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Feb 18 18:40:02 EST 2020

plan9: rearrange style-related things into a single array

--- a/plan9.c
+++ b/plan9.c
@@ -82,39 +82,27 @@
 static int mode = Minsert;
 static long framedev; /* frame deviation in ms */
 
-static char *dotstyles[Numstyles] = {
-	[Sfancy] = "fancy dots",
-	[Splain] = "plain dots",
-	[Snone] = "no dots",
-};
-
-static char *rulerstyles[Numstyles] = {
-	[Sfancy] = "fancy rulers",
-	[Splain] = "plain rulers",
-	[Snone] = "no rulers",
-};
-
-static Rune dot[Numstyles] = {
-	[Sfancy] = L'·',
-	[Splain] = '.',
-	[Snone] = ' ',
-};
-
-static Rune ruler[Numstyles][9] = {
+static struct {
+	struct {
+		char *menu;
+		Rune r;
+	}dot;
+	struct {
+		char *menu;
+		Rune r[9];
+	}ruler;
+}styles[Numstyles] = {
 	[Sfancy] = {
-		L'┌', L'┬', L'┐',
-		L'├', L'┼', L'┤',
-		L'└', L'┴', L'┘',
+		.dot = {"fancy dots", L'·'},
+		.ruler = {"fancy rulers", {L'┌', L'┬', L'┐', L'├', L'┼', L'┤', L'└', L'┴', L'┘'}},
 	},
 	[Splain] = {
-		'+', '+', '+',
-		'+', '+', '+',
-		'+', '+', '+',
+		.dot = {"plain dots", '.'},
+		.ruler = {"plain rulers", {'+', '+', '+', '+', '+', '+', '+', '+', '+'}},
 	},
 	[Snone] = {
-		' ', ' ', ' ',
-		' ', ' ', ' ',
-		' ', ' ', ' ',
+		.dot = {"no dots", ' '},
+		.ruler = {"no rulers", {0}},
 	},
 };
 
@@ -534,13 +522,13 @@
 			fg = selected ? Dfinv : (grouphl ? Dbinv: Dfmed);
 
 			if (c == '.')
-				c = dot[dotstyle];
+				c = styles[dotstyle].dot.r;
 
-			if (c == dot[dotstyle] && attr == 0) {
+			if (c == styles[dotstyle].dot.r && attr == 0) {
 				if ((x % rulers.x) == 0 && (y % rulers.y) == 0) {
 					rx = !!x + (x + 1) / field.width;
 					ry = !!y + (y + 1) / field.height;
-					c = rulerstyle == Snone ? dot[dotstyle] : ruler[rulerstyle][ry*3+rx];
+					c = rulerstyle == Snone ? styles[dotstyle].dot.r : styles[rulerstyle].ruler.r[ry*3+rx];
 				}
 				fg = Dflow;
 			} else if (!selected && !grouphl) {
@@ -1073,8 +1061,8 @@
 			} else if (m.buttons == 5) { /* paste */
 				selpaste();
 			} else if (m.buttons == 4) { /* menu */
-				menu3i[Menu3dotstyle] = dotstyles[(dotstyle+1) % Numstyles];
-				menu3i[Menu3rulerstyle] = rulerstyles[(rulerstyle+1) % Numstyles];
+				menu3i[Menu3dotstyle] = styles[(dotstyle+1) % Numstyles].dot.menu;
+				menu3i[Menu3rulerstyle] = styles[(rulerstyle+1) % Numstyles].ruler.menu;
 				n = menuhit(3, mctl, &menu3, nil);
 				snprint(tmp, sizeof(tmp), "%s", filename);
 				if (n == Menu3load) {