Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package wow.doge.mygame.utils
import java.io.PrintStream import java.io.OutputStream import java.io.ByteArrayOutputStream import scalafx.scene.control.TextArea import wow.doge.mygame.implicits._ import cats.effect.Resource import monix.bio.Task
trait JFXConsoleStreamable[T] { def println(inst: T, text: String): Unit def print(inst: T, text: String): Unit }
class JFXConsoleStream[T]( outputStream: OutputStream, val config: JFXConsoleStream.Config = JFXConsoleStream.Config.default, control: T )(implicit jcs: JFXConsoleStreamable[T] ) extends PrintStream(outputStream, true) { private lazy val defaultOut = System.out override def println(text: String): Unit = if (config.exclusive) { jcs.println(control, text + "\n") } else { defaultOut.println(text) jcs.println(control, text + "\n") } override def print(text: String): Unit = jcs.println(control, text) }
object JFXConsoleStream {
/**
* for future use */ case class Config(exclusive: Boolean = false) object Config { lazy val default = Config() }
def textAreaStream(ta: TextArea) = Resource.make( Task( new JFXConsoleStream( outputStream = new ByteArrayOutputStream(), control = ta ) ) )(s => Task(s.close())) }
|