With javascript I can print styled logs on the console like e.g. this:
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
which will result in:
Is there any way I can do the same using Scala.js? The standard println
does not seem to have this functionality.
*Edit: Of course one could always use scala.scalajs.js.eval
for such cases but I'd prefer a more "scala native" way:
js.eval("""
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
""")
With javascript I can print styled logs on the console like e.g. this:
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
which will result in:
Is there any way I can do the same using Scala.js? The standard println
does not seem to have this functionality.
*Edit: Of course one could always use scala.scalajs.js.eval
for such cases but I'd prefer a more "scala native" way:
js.eval("""
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
""")
Share
Improve this question
edited Oct 23, 2018 at 9:47
Florian Baierl
asked Oct 23, 2018 at 9:39
Florian BaierlFlorian Baierl
2,4914 gold badges27 silver badges53 bronze badges
2 Answers
Reset to default 7scala-js-dom project provides type safe bindings for this and most other browser features:
import org.scalajs.dom
dom.console.log("%c Oh my heavens! ", "background: #222; color: #bada55")
No need to use js.Dynamic
You can use console.log
using, for example, the dynamically typed API:
js.Dynamic.global.console.log("%c Oh my heavens!",
"background: #222; color: #bada55")