GithubHelp home page GithubHelp logo

No colours when run on Node.js about scribe HOT 14 CLOSED

keynmol avatar keynmol commented on June 19, 2024
No colours when run on Node.js

from scribe.

Comments (14)

armanbilge avatar armanbilge commented on June 19, 2024 1

Seems fine :)

from scribe.

keynmol avatar keynmol commented on June 19, 2024 1

That did it, thanks!

from scribe.

keynmol avatar keynmol commented on June 19, 2024

Also, as another (but much harder to reproduce) datapoint, my tooling captures STDERR from a node process which Scribe logs to, and I get this:
image

Do you know what those %c symbols are? I couldn't reproduce in a standalone node run.

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

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.

from scribe.

keynmol avatar keynmol commented on June 19, 2024

Let me know if the code above fixes it and we can work toward a patch to make it automatic.

This worked, thank you!

that is specifically designed for rich output to the browser console

nice, I had no idea %c existed and that it applies CSS

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

Now, we just have to come up with a way to differentiate between running in the browser and running in Node.js. Any ideas? :)

from scribe.

keynmol avatar keynmol commented on June 19, 2024

I would suggest using the hack outlined in detect-node package: https://github.com/iliakan/detect-node/blob/master/index.js#L2

I actually mentioned it in the original issue :)

basically if there's a global process object, then it's a Node.js environment (it seems)

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

from scribe.

keynmol avatar keynmol commented on June 19, 2024

@armanbilge linked to one already in use: https://github.com/http4s/http4s-crypto/blob/a04b435d8e06c907bdcc2233b61c43ffa41a3ccb/crypto/js/src/main/scala/org/http4s/crypto/facade/package.scala#L24-L27

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

Thanks, I'll take a look when I have a chance or feel free to submit a PR.

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

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?

from scribe.

armanbilge avatar armanbilge commented on June 19, 2024

No, sys.env does not work in Scala.js, even on Node.js. You'd have to use process.env.

https://github.com/typelevel/cats-effect/blob/a7ca501029413ec1d62c0b6ea41893043852ea75/std/js/src/main/scala/cats/effect/std/EnvCompanionPlatform.scala

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

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

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

I've created this PR: #384

Feel free to make any suggested changes before I merge and release.

from scribe.

darkfrog26 avatar darkfrog26 commented on June 19, 2024

Release 3.10.7 includes the fix for this. @keynmol can you please verify this automatically works now before you close this ticket? Thanks!

from scribe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.