From f6786b8895969d5bb9fcf762b70087c9605a1102 Mon Sep 17 00:00:00 2001 From: jelveh Date: Wed, 21 May 2025 18:50:15 -0700 Subject: [PATCH] introduce the `puter.log()` method --- src/puter-js/src/index.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index 86f52dc29..47f9e7f5f 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -524,10 +524,28 @@ export default window.puter = (function() { print = function(...args){ for(let arg of args){ - const textNode = document.createTextNode(arg); - document.body.appendChild(textNode); + document.body.innerHTML += arg; } } + + log = function(...args) { + let container = document.getElementById("--puter-printbox"); + if (!container) { + document.body.innerHTML += `
` + container = document.getElementById("--puter-printbox"); + } + + // Check if the last argument is an options object + const options = typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null ? args.pop() : { newline: false }; + + // Process each argument + for(let arg of args) { + container.innerText += arg; + if (options.newline) { + container.innerText += '\n'; + } + } + }; } // Create a new Puter object and return it