Origin tweet: https://twitter.com/li_haoyi/status/804657647446204417
A #Scala compiler plugin to add a nice banner every time it compiles things so it's easier to see in the SBT logspam
Origin tweet: https://twitter.com/li_haoyi/status/804657647446204417
A #Scala compiler plugin to add a nice banner every time it compiles things so it's easier to see in the SBT logspam
package demo | |
import scala.tools.nsc.io.AbstractFile | |
import scala.tools.nsc.{Global, Phase} | |
import scala.tools.nsc.plugins.{Plugin, PluginComponent} | |
class DemoPlugin(val global: Global) extends Plugin { | |
import global._ | |
override def init(options: List[String], error: String => Unit): Boolean = true | |
val name = "demo" | |
val description = "a plugin" | |
val components = List[PluginComponent](DemoComponent) | |
private object DemoComponent extends PluginComponent { | |
val global = DemoPlugin.this.global | |
import global._ | |
override val runsAfter = List("parser") | |
override val runsBefore = List("namer") | |
val phaseName = "Demo" | |
override def newPhase(prev: Phase) = new GlobalPhase(prev) { | |
override def run() = { | |
val count = global.currentRun.units.length | |
val x: Iterator[Seq[String]] = global.currentRun.units.map(_.source.file.path.split("/")) | |
var start = x.next() | |
for(next <- x){ | |
for(i <- next.indices){ | |
if (i < start.length && start.lift(i) != next.lift(i)){ | |
start = start.take(i) | |
} | |
} | |
} | |
val cwd = new java.io.File("").getAbsolutePath.split("/") | |
if (start.startsWith(cwd)) start = start.drop(cwd.length) | |
val msg = s"Compiling $count files in ${start.mkString("/")}" | |
val spaces = " " * ((90 - msg.length) / 2) | |
global.reporter.echo( | |
scala.Console.BLUE_B + | |
spaces + msg + spaces + | |
scala.Console.RESET | |
) | |
} | |
def name: String = phaseName | |
def apply(unit: global.CompilationUnit): Unit = {} | |
} | |
} | |
} |