shithub: purgatorio

Download patch

ref: 87d72e7e8614d96b4f61adae5fb05b0534231c4c
parent: eb0e026c241bd3afc6a10a6e2c7417de1b91f7e8
author: henesy <devnull@localhost>
date: Fri Dec 11 20:02:29 EST 2020

wm/dir, wm/toolbar: do not use array indices for font insertion, use arrays(2) and string(2)

--- a/appl/wm/dir.b
+++ b/appl/wm/dir.b
@@ -31,6 +31,12 @@
 
 include "env.m";
 
+include "arrays.m";
+	arrays: Arrays;
+
+include "string.m";
+	strings: String;
+
 Fontwidth: 	int;
 font:		string;
 Xwidth:		con 50;
@@ -62,13 +68,12 @@
 
 	"canvas .fc.c -relief sunken -yscrollincrement 25"+
 		" -borderwidth 2 -width 10c -height 300"+
-		" -yscrollcommand {.fc.scroll set}",
-		# Add -font here (2)
+		" -yscrollcommand {.fc.scroll set} $font",
 
 	"frame .mbar",
 	"menubutton .mbar.opt -text {Options} -menu .opt",
-	".mbar configure", # Add font (5)
-	".mbar.opt configure", # Add font (6)
+	".mbar configure $font",
+	".mbar.opt configure $font",
 	"pack .mbar.opt -side left",
 	"pack .fc.scroll -side right -fill y",
 	"pack .fc.c -fill both -expand 1",
@@ -81,7 +86,7 @@
 
 	# Build the options menu
 	"menu .opt",
-	".opt configure", # Add font (15)
+	".opt configure $font",
 	".opt add radiobutton -text {by name}"+
 		" -variable sort -value n -command {send opt sort}",
 	".opt add radiobutton -text {by access}"+
@@ -146,6 +151,8 @@
 	if(plumbmsg != nil && plumbmsg->init(1, nil, 0) >= 0)
 		plumbed = 1;
 	environ := load Env Env->PATH;
+	arrays = load Arrays Arrays->PATH;
+	strings = load String String->PATH;
 
 	font = environ->getenv("font");
 	if(font == nil)
@@ -181,10 +188,7 @@
 		getdir(t, hd argv);
 
 	# Patch in font (need a replaceall?)
-	dirwin_cfg[2] += font;
-	dirwin_cfg[5] += font;
-	dirwin_cfg[6] += font;
-	dirwin_cfg[15] += font;
+	dirwin_cfg = arrays->map(dirwin_cfg, fontify);
 
 	for (c:=0; c<len dirwin_cfg; c++)
 		tk->cmd(t, dirwin_cfg[c]);
@@ -534,4 +538,9 @@
 	if(n < 0) 
 		return "Anon";
 	return string buf[0:n];
+}
+
+# Substitute '$font' with font string
+fontify(s: string): string {
+	return strings->replace(s, "$font", font, -1);
 }
--- a/appl/wm/toolbar.b
+++ b/appl/wm/toolbar.b
@@ -17,11 +17,15 @@
 	shell: Sh;
 	Listnode, Context: import shell;
 
+include "arg.m";
+
+include "env.m";
+
 include "string.m";
 	str: String;
 
-include "arg.m";
-include "env.m";
+include "arrays.m";
+	arrays: Arrays;
 
 myselfbuiltin: Shellbuiltin;
 
@@ -85,6 +89,9 @@
 	env := load Env Env->PATH;
 	if(env == nil)
 		badmodule(Env->PATH);
+	arrays = load Arrays Arrays->PATH;
+	if(arrays == nil)
+		badmodule(Arrays->PATH);
 
 	myselfbuiltin = load Shellbuiltin "$self";
 	if (myselfbuiltin == nil)
@@ -518,7 +525,7 @@
 	"scrollbar .cons.scroll -command {.cons.t yview}",
 
 	"text .cons.t -width 60w -height 15w -bg white "+
-		"-fg black -yscrollcommand {.cons.scroll set} ", 	# Need the font appended later
+		"-fg black -yscrollcommand {.cons.scroll set} $font",
 		#"",
 
 	"pack .cons.scroll -side left -fill y",
@@ -552,7 +559,7 @@
 	(top, titlectl) := tkclient->toplevel(ctxt, "", "Log", tkclient->Appl); 
 
 	# Patch in font - why was this an array to start?
-	con_cfg[2] += font;
+	con_cfg = arrays->map(con_cfg, fontify);
 
 	for(i := 0; i < len con_cfg; i++)
 		cmd(top, con_cfg[i]);
@@ -612,4 +619,8 @@
 	}
 
 	tk->cmd(top, ".cons.t see end; update");
+}
+
+fontify(s: string): string {
+	return str->replace(s, "$font", font, -1);
 }