diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-12 00:10:39 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-12 00:11:33 -0800 |
commit | 865c8fc2c11ef5f364315be197226723a3a47821 (patch) | |
tree | cc9b56e41b61a0f25e31664430feb75cef4e853d /core/src/main/scala | |
parent | dea3b0d87facc657d42072ecffa791eaedc39017 (diff) | |
download | mill-865c8fc2c11ef5f364315be197226723a3a47821.tar.gz mill-865c8fc2c11ef5f364315be197226723a3a47821.tar.bz2 mill-865c8fc2c11ef5f364315be197226723a3a47821.zip |
Clean up `Logger.scala` a bit
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/mill/util/Logger.scala | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/core/src/main/scala/mill/util/Logger.scala b/core/src/main/scala/mill/util/Logger.scala index 316e17ff..1cec82ff 100644 --- a/core/src/main/scala/mill/util/Logger.scala +++ b/core/src/main/scala/mill/util/Logger.scala @@ -44,6 +44,16 @@ object DummyLogger extends Logger { def ticker(s: String) = () } +class CallbackStream(wrapped: OutputStream, f: () => Unit) extends OutputStream{ + override def write(b: Array[Byte]): Unit = { f(); wrapped.write(b) } + + override def write(b: Array[Byte], off: Int, len: Int): Unit = { + f() + wrapped.write(b, off, len) + } + + def write(b: Int) = {f(); wrapped.write(b)} +} case class PrintLogger(colored: Boolean, colors: ammonite.util.Colors, outStream: PrintStream, @@ -51,41 +61,15 @@ case class PrintLogger(colored: Boolean, errStream: PrintStream) extends Logger { var lastLineTicker = false + def falseTicker[T](t: T) = { + lastLineTicker = false + t + } override val errorStream = new PrintStream( - new OutputStream { - override def write(b: Array[Byte]): Unit = { - lastLineTicker = false - errStream.write(b) - } - - override def write(b: Array[Byte], off: Int, len: Int): Unit = { - lastLineTicker = false - errStream.write(b, off, len) - } - - def write(b: Int) = { - lastLineTicker = false - errStream.write(b) - } - } + new CallbackStream(errStream, () => lastLineTicker = false) ) override val outputStream = new PrintStream( - new OutputStream { - override def write(b: Array[Byte]): Unit = { - lastLineTicker = false - outStream.write(b) - } - - override def write(b: Array[Byte], off: Int, len: Int): Unit = { - lastLineTicker = false - outStream.write(b, off, len) - } - - def write(b: Int) = { - lastLineTicker = false - outStream.write(b) - } - } + new CallbackStream(outStream, () => lastLineTicker = false) ) |