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: support console.log with colors #609

Open
ahaoboy opened this issue Jul 16, 2024 · 3 comments
Open

feat: support console.log with colors #609

ahaoboy opened this issue Jul 16, 2024 · 3 comments

Comments

@ahaoboy
Copy link
Contributor

ahaoboy commented Jul 16, 2024

Will it support colored console.log output? Using different colors for different types will make it easier to distinguish

https://github.com/ahaoboy/deno-ext/tree/main/deno-console

If someone wants to use a styled console, they can use the following code to override the original implementation

import { Console } from '@deno-ext/console'
const encoder = new TextEncoder();
const print = s => tjs.stdout.write(encoder.encode(s));
globalThis.console = new Console(print)

console.log(1)
@saghul
Copy link
Owner

saghul commented Jul 16, 2024

Fun fact! There should be color support in there already, since we took the inspect util from Node:

export function inspect(obj, opts) {

It's just not enabled by default.

@ahaoboy
Copy link
Contributor Author

ahaoboy commented Jul 16, 2024

console.log is a very cumbersome thing, e.g. in some scenarios it may be better to output part of the information, otherwise it will be cluttered with a lot of useless information

> new Uint8Array(1000)
Uint8Array(1000) [
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0,
  ... 900 more items
]

@saghul
Copy link
Owner

saghul commented Jul 16, 2024

Agreed. Note that the above is the REPL, which doesn't use console.log for its output, even though they both end up sending their output to tjs.stdout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants