Skip to content

feat(runtime): Implement console.Console - #5448

Merged
paperclover merged 9 commits into
mainfrom
dave/console-constructor
Sep 18, 2023
Merged

paperclover merged 9 commits into
mainfrom
dave/console-constructor

Conversation

@paperclover

Copy link
Copy Markdown
Contributor

What does this PR do?

Copies node's implementation for console.Console, which gives the console interface but piped to any node stream. This enables:

import { Console } from "console";
import { createWriteStream } from "fs";

const writer = new Console({ stdout: createWriteStream("log.txt") });

writer.log("hello");
writer.log("world", { x: 2 });

and this will write to the file

hello
world { x: 2 }

TODO:

  • Tests.
  • Bug with printing will reveal the options object somehow.
  • Self-Review.

@paperclover
paperclover marked this pull request as ready for review September 16, 2023 03:21
Comment thread src/js/node/util.js
if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
for (var i = 1; i < arguments.length; i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixes formatWithOptions({colors:true}, {x:2))

);
};

var isZeroWidthCodePoint = code => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really wish this was like 95% less javascript

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear you.

// Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js
// License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore
// Matches all ansi escape code sequences in a string
var ansiPattern =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to be extremely slow due to interpretor overhead

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but still.. it's merged?

Comment thread src/bun.js/bindings/ZigGlobalObject.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants