-
Notifications
You must be signed in to change notification settings - Fork 39
/
Platform.scala
42 lines (29 loc) · 1.3 KB
/
Platform.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package scribe
import scribe.output.format.{ANSIOutputFormat, ASCIIOutputFormat, OutputFormat, RichBrowserOutputFormat}
import scribe.writer.{BrowserConsoleWriter, Writer}
import scala.concurrent.ExecutionContext
import scala.scalajs.js
import scala.scalajs.js.Dictionary
import scala.util.Try
object Platform extends PlatformImplementation {
def isJVM: Boolean = false
def isJS: Boolean = true
def isNative: Boolean = false
// $COVERAGE-OFF$
lazy val isNodeJS: Boolean = Try(js.Dynamic.global.process.release.name.asInstanceOf[String]).toOption.contains("node")
def init(): Unit = {}
def console: JavaScriptConsole = js.Dynamic.global.console.asInstanceOf[JavaScriptConsole]
private def processEnv: Dictionary[Any] = Try(js.Dynamic.global.process.env.asInstanceOf[js.Dictionary[Any]])
.getOrElse(js.Dictionary.empty)
// $COVERAGE-ON$
override def env(key: String): Option[String] = processEnv.get(key).map(_.toString)
override def outputFormat(): OutputFormat = if (isNodeJS) {
super.outputFormat()
} else {
RichBrowserOutputFormat
}
override def consoleWriter: Writer = BrowserConsoleWriter
override val columns: Int = 120 + columnsAdjust
override def rows: Int = -1
override def executionContext: ExecutionContext = scala.scalajs.concurrent.JSExecutionContext.queue
}