chiark / gitweb /
webstead: slightly more robust invocation of bedstead
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 15 Oct 2025 22:10:23 +0000 (23:10 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 13 Jan 2026 21:42:18 +0000 (21:42 +0000)
Now we don't assume that stdout is line-buffered and that we'll
therefore get a single call to print().  Instead, we collect up all
the output in a string and use it when the program exits.

webstead.xhtml

index 3b582e4881ee06c530a4e33e12c4557e9aa418c7..0515640e9d16b201cba1037f45fe45939cea3a5d 100644 (file)
         }
         if (c_update_needed)
             document.getElementById("c").value = ` {"${cstr}", U() },`;
+        var charstring = "";
         Bedstead({
-            arguments: args,
-            print: function(charstring) {
-                document.getElementById("rendered")
-                    .setAttribute("d", charstring
-                                  .replaceAll(/<!--(?:[^-]|-[^-])*-->/g, "")
-                                  .replace(/^.* [hv]stem /, "")
-                                  .replace(/^cntrmask [01]* /, "")
-                                  .replaceAll(/(\S+ +\S+ +)rmoveto/g, "m$1")
-                                  .replaceAll(/ rlineto/g, "")
-                                  .replace(/ endchar/, ""));
-            }
+            arguments: args,            
+            print: printed => charstring += printed
+        }).then(() => {
+            document.getElementById("rendered")
+                .setAttribute("d", charstring
+                              .replaceAll(/<!--(?:[^-]|-[^-])*-->/g, "")
+                              .replace(/^.* [hv]stem /, "")
+                              .replace(/^cntrmask [01]* /, "")
+                              .replaceAll(/(\S+ +\S+ +)rmoveto/g, "m$1")
+                              .replaceAll(/ rlineto/g, "")
+                              .replace(/ endchar/, ""));
         });
     }
     function from_c(c) {