commit 679128c

ohmu  ·  2026-07-17 08:09:16 +0300 MSK
parent 480b74f
added text configuration, no more recompilation
15 files changed,  +208, -166
+11, -14
 1@@ -12,8 +12,7 @@
 2 
 3 #include "dat.h"
 4 #include "fns.h"
 5-#include "config.h"
 6-#include "theme.h"
 7+#include "parser.h"
 8 
 9 /* for generating syms in mkfile only: */
10 #include <bio.h>
11@@ -34,6 +33,7 @@ int		timefmt(Fmt*);
12 Reffont	**fontcache;
13 int		nfontcache;
14 char	wdir[512] = ".";
15+char    *fontnames[2];
16 Reffont	*reffonts[2];
17 int		snarffd = -1;
18 int		mainpid;
19@@ -140,8 +140,7 @@ threadmain(int argc, char *argv[])
20 		threadexitsall("usage");
21 	}ARGEND
22 
23-	fontnames[0] = estrdup(fontnames[0]);
24-	fontnames[1] = estrdup(fontnames[1]);
25+	init_config();
26 
27 	quotefmtinstall();
28 	fmtinstall('t', timefmt);
29@@ -984,21 +983,19 @@ iconinit(void)
30 	Image *tmp;
31 
32 	if(tagcols[BACK] == nil) {
33-#ifndef ENABLE_PASTELS
34-		tagcols[BACK]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TAGBG);
35-#else
36-        tagcols[BACK] = allocimagemix(display, C_TAGBG, C_MIX);
37-#endif
38+        if (ENABLE_PASTELS)
39+    		tagcols[BACK]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TAGBG);
40+        else
41+            tagcols[BACK] = allocimagemix(display, C_TAGBG, C_MIX);
42 		tagcols[HIGH]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TAGHLBG);
43 		tagcols[BORD]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_COLBUTTON);
44 		tagcols[TEXT]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TAGFG);
45 		tagcols[HTEXT]	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TAGHLFG);
46 
47-#ifndef ENABLE_PASTELS
48-		textcols[BACK] 	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TXTBG);
49-#else
50-		textcols[BACK] = allocimagemix(display, C_TXTBG, C_MIX);
51-#endif
52+        if (ENABLE_PASTELS)
53+    		textcols[BACK] 	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TXTBG);
54+        else
55+		    textcols[BACK] = allocimagemix(display, C_TXTBG, C_MIX);
56 		textcols[HIGH] 	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TXTHLBG);
57 		textcols[BORD] 	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_SCROLLBG);
58 		textcols[TEXT] 	= allocimage(display, Rect(0,0,1,1), RGBA32, 1, C_TXTFG);
+41, -0
 1@@ -0,0 +1,41 @@
 2+" Copy this as $HOME/.acmerc
 3+
 4+
 5+" settings
 6+
 7+mainfont       /home/glenda/src/fonts/GoMonoNF/13a/font
 8+monofont       /home/glenda/src/fonts/GoMonoNF/13a/font
 9+dumppath       /home/glenda/.acme.dump
10+shell          /bin/rc
11+
12+autoindent     1
13+swpscrllbtns   0
14+clicktofocus   0
15+
16+" theming
17+
18+pastels 1
19+
20+mix     eaddd0
21+
22+root    f6efe5
23+
24+tagbg   f6efe5
25+tagfg   5c4a3a
26+htagbg  b08060
27+htagfg  ffffff
28+
29+txtbg   f6efe5
30+txtfg   5c4a3a
31+htxtbg  b08060
32+htxtfg  ffffff
33+
34+winbtn  6b5445
35+colbtn  8c7a64
36+tmpbtn  8c7a64
37+scrlbg  9c8271
38+
39+border  8c7a64
40+
41+btn2hl  b08060
42+btn3hl  b08060
+1, -1
1@@ -9,7 +9,7 @@
2 #include <fcall.h>
3 #include <plumb.h>
4 #include <libsec.h>
5-#include "theme.h"
6+#include "parser.h"
7 #include "dat.h"
8 #include "fns.h"
9 
+0, -52
 1@@ -1,52 +0,0 @@
 2-/*
 3- *  fontnames-array takes two fonts, first one
 4- *  it treats as a proportional-width font and uses
 5- *  everywhere possible and as a main UI font, while
 6- *  the second font it treats as a fixed-width font,
 7- *  changeable to any text window by executing `Font`
 8- *  from tag window.
 9- *
10- *  Note: `Font` can also be executed
11- *  with arguments with any `fontsrv -p .` approved
12- *  fonts, thus allowing you to experiment with font
13- *  sizes and whether you want anti-aliasing or not.
14- */
15-
16-char *fontnames[2] = {
17-    "/home/glenda/src/fonts/GoMonoNF/15a/font",
18-    "/home/glenda/src/fonts/GoMonoNF/15a/font",
19-};
20-
21-/* 
22- * path of acme.dump file 
23- */
24-
25-char *dump_path = "/home/glenda/.acme.dump";
26-
27-char *acmeshell = "/bin/rc";
28-
29-/*
30- *  globalautoindent tries to guess where to
31- *  indent by the context of the previous line.
32- *
33- *  comes highly suggested.
34- */
35-
36-int globalautoindent	= 1;
37-
38-/*
39- *  swapping scroll buttons makes B1 scroll down
40- *  instead of up and B2 up instead of down
41- */
42-
43-int	swapscrollbuttons	= 0;
44-
45-/*
46- *  bartflag triggers quote unquote experimental
47- *  mode, in which instead of mouse following focus
48- *  from window to window etc. it in fact, does not.
49- *
50- *  comes highly suggested.
51- */
52-
53-int bartflag			= 1;
+0, -6
 1@@ -533,8 +533,6 @@ Text			*argtext;
 2 Text			*mousetext;	/* global because Text.close needs to clear it */
 3 Text			*typetext;		/* global because Text.close needs to clear it */
 4 Text			*barttext;		/* shared between mousetask and keyboardthread */
 5-extern int			bartflag;
 6-extern int			swapscrollbuttons;
 7 Window		*activewin;
 8 Column		*activecol;
 9 Buffer		snarfbuf;
10@@ -543,16 +541,12 @@ int			fsyspid;
11 char			*cputype;
12 char			*objtype;
13 char			*home;
14-char			*acmeshell;
15-extern char			*fontnames[2];
16 Image		*tagcols[NCOL];
17 Image		*textcols[NCOL];
18 extern char		wdir[]; /* must use extern because no dimension given */
19 int			editing;
20 int			erroutfd;
21 int			messagesize;		/* negotiated in 9P version setup */
22-extern int			globalautoindent;
23-extern char     *dump_path;
24 int			dodollarsigns;
25 char*		mtpt;
26 
+1, -0
1@@ -13,6 +13,7 @@
2 #include <9pclient.h>
3 #include "dat.h"
4 #include "fns.h"
5+#include "parser.h"
6 
7 Buffer	snarfbuf;
8 
+0, -1
1@@ -6,7 +6,6 @@ mk clean && NPROC=$(nproc) mk
2 if [ -f "o.acme" ]; then
3     doas rm -f "$path/acme"
4     doas cp o.acme "$path/acme"
5-	doas cp o.win  "$path/win"
6     echo "ok"
7 	mk clean
8 else
+1, -0
1@@ -13,6 +13,7 @@
2 #include <libsec.h>
3 #include "dat.h"
4 #include "fns.h"
5+#include "parser.h"
6 
7 CFid *plumbsendfid;
8 CFid *plumbeditfid;
+2, -2
 1@@ -26,12 +26,12 @@ OFILES=\
 2 	util.$O\
 3 	wind.$O\
 4 	xfid.$O\
 5+	parser.$O\
 6 
 7 HFILES=dat.h\
 8 	edit.h\
 9 	fns.h\
10-	config.h\
11-    theme.h
12+    parser.h\
13 
14 <$PLAN9/src/mkone
15 <$PLAN9/src/mkdirs
+112, -0
  1@@ -0,0 +1,112 @@
  2+/* I'm so ashamed of this code, sorry */
  3+
  4+#include <stdio.h>
  5+#include <string.h>
  6+#include <stdlib.h> 
  7+#include <inttypes.h>
  8+#include "parser.h"
  9+
 10+char
 11+*parse_key_value(FILE *file, char const *desired_name)
 12+{ 
 13+    char line[256];
 14+    char name[128];
 15+    char val[128];
 16+
 17+    rewind(file);
 18+
 19+    while (fgets(line, sizeof(line), file)) {
 20+        if (line[0] == '\n' || line[0] == '\0') continue;
 21+        
 22+        if (sscanf(line, "%127s %127[^\n]", name, val) == 2) {
 23+            if (strcmp(name, desired_name) == 0) {
 24+                return strdup(val);
 25+            }
 26+        }
 27+    }
 28+    return NULL;
 29+}
 30+
 31+uint32_t
 32+get_color(FILE *f, char *key, uint32_t def)
 33+{
 34+	char *temp = parse_key_value(f, key);
 35+	if (!temp)
 36+		return def;
 37+	uint32_t color = strtoul(temp, NULL, 16) << 8 | 0xFF;
 38+	free(temp);
 39+	return color;
 40+}
 41+
 42+int
 43+get_int_value(FILE *f, char *key, int def)
 44+{
 45+    int result;
 46+    char *temp = parse_key_value(f, key);
 47+    if (temp == NULL)
 48+        return def;
 49+    else
 50+        result = atoi(temp);
 51+        free(temp);
 52+        return result;
 53+}
 54+
 55+void
 56+init_config(void)
 57+{
 58+    char *home = getenv("HOME");
 59+    char path[1024];
 60+    if (!home) {
 61+        fprintf(stderr, "$HOME not set\n");
 62+        exit(1);
 63+    }
 64+    snprintf(path, sizeof(path), "%s/.acmerc", home);
 65+	FILE *f = fopen(path, "r");
 66+	if (!f) {
 67+		fprintf(stderr, "can't open file\n");
 68+        exit(1);
 69+    }
 70+    ENABLE_PASTELS = get_int_value(f, "pastels", 1);
 71+    C_MIX = get_color(f, "mix", 0xFFFFFFFF);
 72+    C_ROOTBG = get_color(f, "root", 0xFFFFFFFF);
 73+    C_BORDER = get_color(f, "border", 0x000000FF);
 74+    C_ROWSBG = get_color(f, "rowsbg", 0x000000FF);
 75+    C_TAGBG = get_color(f, "tagbg", 0x87CEEBFF);
 76+    C_TAGFG = get_color(f, "tagfg", 0x000000FF);
 77+    C_TAGHLBG = get_color(f, "htagbg", 0x8FBC8FFF);
 78+    C_TAGHLFG = get_color(f, "htagfg", 0x000000FF);
 79+    C_TXTBG = get_color(f, "txtbg", 0xFFFFE0FF);
 80+    C_TXTFG = get_color(f, "txtfg", 0x000000FF);
 81+    C_TXTHLBG = get_color(f, "htxtbg", 0x8B8B00FF);
 82+    C_TXTHLFG = get_color(f, "htxtfg", 0x000000FF);
 83+    C_WINBUTTON = get_color(f, "winbtn", 0x8A2BE2FF);
 84+    C_COLBUTTON = get_color(f, "colbtn", 0x8A2BE2FF);
 85+    C_TMPBUTTON = get_color(f, "tmpbtn", 0x0000CDFF);
 86+    C_SCROLLBG = get_color(f, "scrlbg", 0x9ACD32FF);
 87+    C_BUTTON2HL = get_color(f, "btn2hl", 0xAA0000FF);
 88+    C_BUTTON3HL = get_color(f, "btn3hl", 0x006600FF);
 89+
 90+    mainfont = parse_key_value(f, "mainfont");
 91+    monofont = parse_key_value(f, "monofont");
 92+    dump_path = parse_key_value(f, "dumppath");
 93+    acmeshell = parse_key_value(f, "shell");
 94+    if (!acmeshell || !monofont || !mainfont || !dump_path) {
 95+        fprintf(stderr, "not all required variables found in config\n");
 96+        exit(1);
 97+    }
 98+
 99+    if (mainfont) {
100+        free(fontnames[0]);
101+        fontnames[0] = strdup(mainfont);
102+    }
103+    if (monofont) {
104+        free(fontnames[1]);
105+        fontnames[1] = strdup(monofont);
106+    }
107+
108+    globalautoindent = get_int_value(f, "autoindent", 1);
109+    swapscrollbuttons = get_int_value(f, "swpscrllbtns", 0);
110+    bartflag = get_int_value(f, "clicktofocus", 1);
111+
112+	fclose(f);
113+}
+36, -0
 1@@ -0,0 +1,36 @@
 2+#include <stdio.h>
 3+
 4+char *parse_key_value(FILE *file, char const *desired_name);
 5+uint32_t get_color(FILE *f, char *key, uint32_t def);
 6+void init_config(void);
 7+
 8+int ENABLE_PASTELS;
 9+uint32_t C_MIX;
10+uint32_t C_ROOTBG;
11+uint32_t C_BORDER;
12+uint32_t C_ROWSBG;
13+uint32_t C_TAGBG;
14+uint32_t C_TAGFG;
15+uint32_t C_TAGHLBG;
16+uint32_t C_TAGHLFG;
17+uint32_t C_TXTBG;
18+uint32_t C_TXTFG;
19+uint32_t C_TXTHLBG;
20+uint32_t C_TXTHLFG;
21+uint32_t C_WINBUTTON;
22+uint32_t C_COLBUTTON;
23+uint32_t C_TMPBUTTON;
24+uint32_t C_SCROLLBG;
25+uint32_t C_BUTTON2HL;
26+uint32_t C_BUTTON3HL;
27+
28+char *mainfont;
29+char *monofont;
30+char *fontnames[2];
31+char *dump_path;
32+char *acmeshell;
33+
34+int globalautoindent;
35+int bartflag;
36+int swapscrollbuttons;
37+
+1, -1
1@@ -10,7 +10,7 @@
2 #include <bio.h>
3 #include <plumb.h>
4 #include <libsec.h>
5-#include "theme.h"
6+#include "parser.h"
7 #include "dat.h"
8 #include "fns.h"
9 
+0, -89
 1@@ -1,89 +0,0 @@
 2-
 3-/*
 4- *  colors-constants. now let me take a minute to explain
 5- *  them. C_TAGBG/FG/HLBG/HLFG are respectively your tag
 6- *  windows background, foreground, highlighted back- and
 7- *  foreground color. The same exact applies to C_TXT*-
 8- *  variants of the same constant just in this case it handles
 9- *  the colorscheme of the text window.
10- *
11- *  C_WINBUTTON is the button which you adjust your columns
12- *  position with. C_COLBUTTON represents a separate text
13- *  windows button. C_TMPBUTTON is the so-called "dirty"
14- *  or "unclean" -marker aka notifying the file as modified put
15- *  in the middle of C_COLBUTTON. C_SCROLLBG is plain and simple
16- *  your scrollbars background color.
17- *
18- *  the last two defines are for defining the color of the specific
19- *  buttons highlight background.
20- */
21-/*
22-// white default theme
23-#define C_TAGBG			0xFFFFFFFF
24-#define C_TAGFG			0x000000FF
25-#define C_TAGHLBG		0x999999FF
26-#define C_TAGHLFG		0x000000FF
27-
28-#define C_TXTBG			0xFFFFFFFF
29-#define C_TXTFG			0x000000FF
30-#define C_TXTHLBG		0x999999FF
31-#define C_TXTHLFG		0x000000FF
32-
33-#define C_WINBUTTON		0x4d4d4dFF
34-#define C_COLBUTTON		0x55aaaaFF
35-#define C_TMPBUTTON		0x55aaaaFF
36-#define C_SCROLLBG		0x999999FF
37-
38-#define C_BUTTON2HL		0x55aaaaFF
39-#define C_BUTTON3HL		0x55aaaaFF
40-*/
41-/*
42-// PLAN9 theme
43-
44-#define ENABLE_PASTELS
45-#define C_MIX                   DWhite
46-#define C_ROOTBG                0xffffffFF
47-#define C_BORDER                0x000000FF
48-#define C_ROWSBG                0x000000FF
49-#define C_TAGBG                 DPalebluegreen
50-#define C_TAGFG                 0x000000FF
51-#define C_TAGHLBG               DPalegreygreen
52-#define C_TAGHLFG               0x000000FF
53-
54-#define C_TXTBG                 DPaleyellow
55-#define C_TXTFG                 0x000000FF
56-#define C_TXTHLBG               DDarkyellow
57-#define C_TXTHLFG               0x000000FF
58-
59-#define C_WINBUTTON             DPurpleblue
60-#define C_COLBUTTON             DPurpleblue
61-#define C_TMPBUTTON             DMedblue
62-#define C_SCROLLBG              DYellowgreen
63-
64-#define C_BUTTON2HL             0xAA0000FF
65-#define C_BUTTON3HL             0x006600FF
66-*/
67-
68-
69-#define ENABLE_PASTELS
70-#define C_MIX                   0xeaddd0FF
71-
72-#define C_ROOTBG                0xf6efe5FF
73-#define C_TAGBG                 0xf6efe5FF
74-#define C_TAGFG                 0x5c4a3aFF
75-#define C_TAGHLBG               0xb08060FF
76-#define C_TAGHLFG               0xffffffFF
77-
78-#define C_TXTBG                 0xf6efe5FF
79-#define C_TXTFG                 0x5c4a3aFF
80-#define C_TXTHLBG               0xb08060FF
81-#define C_TXTHLFG               0xffffffFF
82-
83-#define C_WINBUTTON             0x6b5445FF
84-#define C_COLBUTTON             0x8c7a64FF
85-#define C_TMPBUTTON             0x8c7a64FF
86-#define C_SCROLLBG              0x9c8271FF
87-#define C_BORDER                0x8c7a64FF
88-
89-#define C_BUTTON2HL             0xb08060FF
90-#define C_BUTTON3HL             0xb08060FF
+1, -0
1@@ -11,6 +11,7 @@
2 #include <libsec.h>
3 #include "dat.h"
4 #include "fns.h"
5+#include "parser.h"
6 
7 static	Point		prevmouse;
8 static	Window	*mousew;
+1, -0
1@@ -11,6 +11,7 @@
2 #include <libsec.h>
3 #include "dat.h"
4 #include "fns.h"
5+#include "parser.h"
6 
7 int	winid;
8