Skip to content

Commit

Permalink
rtlib/emscripten: when running under node.js write directly to proces…
Browse files Browse the repository at this point in the history
…s.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.
  • Loading branch information
rversteegen committed Jun 26, 2023
1 parent 24927ee commit ab729cf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/fb_rtlib.js
Expand Up @@ -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('%(', '%%('));
},

Expand Down

0 comments on commit ab729cf

Please sign in to comment.