最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Scala.js: CSS styled console logs - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 7

scala-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")
发布评论

评论列表(0)

  1. 暂无评论