Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime): Implement console.Console #5448

Merged
merged 9 commits into from
Sep 18, 2023
Merged

Conversation

paperclover
Copy link
Member

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
@@ -27,7 +27,7 @@ var formatRegExp = /%[sdjfoc%]/g;
function formatWithOptions(inspectOptions, f) {
if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
for (var i = 1; i < arguments.length; i++) {
Copy link
Member 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
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

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
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

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?

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