From ab729cfc2890b0dbf604dcaa9981e1bfa472f7b4 Mon Sep 17 00:00:00 2001 From: Ralph Versteegen Date: Sun, 25 Jun 2023 02:25:57 +1200 Subject: [PATCH] rtlib/emscripten: when running under node.js write directly to process.stdout This fixes an extra newline being appended after every PRINT due to console.log(). This is a quick fix just for write() in fb_rtlib.js. No other rtlib functions, e.g. COLOR, are implemented. But there's really no overlap between the existing termlib.js-based fb_rtlib.js and one that directly accesses a tty through node.js, so we should just have a separate .js file for that. --- lib/fb_rtlib.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fb_rtlib.js b/lib/fb_rtlib.js index 7cc1adc632..18493b8f89 100644 --- a/lib/fb_rtlib.js +++ b/lib/fb_rtlib.js @@ -53,10 +53,13 @@ var __fb_rtlib = { if( this.term === null ) { - console.log(text); + // Under node.js write to stdout. console.log adds an extra newline + if( typeof process !== 'undefined' ) + process.stdout.write(text); + else + console.log(text); return; } - this.term.write('%c(' + this.fg_color + ',' + this.bg_color + ')' + text.replace('%(', '%%(')); },