-
Notifications
You must be signed in to change notification settings - Fork 40
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
No colours when run on Node.js #383
Comments
The Scala.js support was originally specifically focused on browser output. Try this to see if it fixes your problems: Logger.root.clearHandlers().withHandler(outputFormat = ANSIOutputFormat).replace() The problem is this: https://github.com/outr/scribe/blob/master/core/js/src/main/scala/scribe/Platform.scala#L20 Which uses: https://github.com/outr/scribe/blob/master/core/js/src/main/scala/scribe/output/format/RichBrowserOutputFormat.scala that is specifically designed for rich output to the browser console. If we can add detection of browser vs Nodes.js, then we can differentiate which output style to use automatically. Let me know if the code above fixes it and we can work toward a patch to make it automatic. |
This worked, thank you!
nice, I had no idea |
Now, we just have to come up with a way to differentiate between running in the browser and running in Node.js. Any ideas? :) |
I actually mentioned it in the original issue :) basically if there's a global Things actually get hairier because there's now at least Deno and Bun runtimes as well, but I think both are marginal in comparison to Node.js |
Thanks, I'll take a look when I have a chance or feel free to submit a PR. |
Is this a reasonable test to validate the availability of ANSI in Node.js? sys.env.contains("TERM") It's what I use on JVM and Native, but I'm not sure if the environment stuff all works the same within Node.js? |
No, |
@armanbilge nice, thanks! How's this look? private def processEnv: Dictionary[Any] = Try(js.Dynamic.global.process.env.asInstanceOf[js.Dictionary[Any]])
.getOrElse(js.Dictionary.empty)
override def env(key: String): Option[String] = processEnv.get(key).map(_.toString) |
Seems fine :) |
I've created this PR: #384 Feel free to make any suggested changes before I merge and release. |
Release |
That did it, thanks! |
Consider this file:
When run via JVM, it's beautiful
![image](https://user-images.githubusercontent.com/1052965/213862869-35fc5ce1-bd42-495f-9319-6ae2ff1a8dd6.png)
When run through JS, it's bleak
![image](https://user-images.githubusercontent.com/1052965/213862888-28a3bebd-e0b8-4b3e-a5ad-25f0ac824c50.png)
To ensure that node.js supports ansi colour codes, I tried this
![image](https://user-images.githubusercontent.com/1052965/213862921-eb176a81-028a-49f1-bbd1-1017ff6a4d21.png)
So it's merely an issue of detecting which JS platform the code runs on.
I would suggest using the hack outlined in detect-node package: https://github.com/iliakan/detect-node/blob/master/index.js#L2
Or may be there's a simpler approach in Scala.js
The text was updated successfully, but these errors were encountered: