mirror of https://github.com/sbt/sbt.git
implement sbt.progress
This implements a logger that grows upward, instead towards bottom.
This commit is contained in:
parent
53c9b84858
commit
9bb244314d
|
|
@ -126,6 +126,7 @@ lazy val utilLogging = (project in internalPath / "util-logging")
|
|||
// Private final class constructors changed
|
||||
exclude[DirectMissingMethodProblem]("sbt.util.InterfaceUtil#ConcretePosition.this"),
|
||||
exclude[DirectMissingMethodProblem]("sbt.util.InterfaceUtil#ConcreteProblem.this"),
|
||||
exclude[ReversedMissingMethodProblem]("sbt.internal.util.ConsoleOut.flush"),
|
||||
),
|
||||
)
|
||||
.configure(addSbtIO)
|
||||
|
|
|
|||
|
|
@ -133,6 +133,21 @@ object ConsoleAppender {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the super shell is enabled.
|
||||
*/
|
||||
lazy val showProgress: Boolean =
|
||||
formatEnabledInEnv && sys.props
|
||||
.get("sbt.progress")
|
||||
.flatMap({ s =>
|
||||
parseLogOption(s) match {
|
||||
case LogOption.Always => Some(true)
|
||||
case LogOption.Never => Some(false)
|
||||
case _ => None
|
||||
}
|
||||
})
|
||||
.getOrElse(true)
|
||||
|
||||
private[sbt] def parseLogOption(s: String): LogOption =
|
||||
s.toLowerCase match {
|
||||
case "always" => LogOption.Always
|
||||
|
|
@ -443,11 +458,17 @@ class ConsoleAppender private[ConsoleAppender] (
|
|||
appendLog(SUCCESS_LABEL_COLOR, Level.SuccessLabel, SUCCESS_MESSAGE_COLOR, message)
|
||||
}
|
||||
|
||||
private final val ScrollUp = "\u001B[S"
|
||||
private final val DeleteLine = "\u001B[2K"
|
||||
private final val CursorLeft1000 = "\u001B[1000D"
|
||||
private def write(msg: String): Unit = {
|
||||
val cleanedMsg =
|
||||
if (!useFormat || !ansiCodesSupported) EscHelpers.removeEscapeSequences(msg)
|
||||
else msg
|
||||
out.println(cleanedMsg)
|
||||
if (!useFormat || !ansiCodesSupported) out.println(EscHelpers.removeEscapeSequences(msg))
|
||||
else {
|
||||
if (ConsoleAppender.showProgress) {
|
||||
out.print(s"$ScrollUp$DeleteLine$msg${CursorLeft1000}")
|
||||
out.flush()
|
||||
} else out.println(msg)
|
||||
}
|
||||
}
|
||||
|
||||
private def appendMessage(level: Level.Value, msg: Message): Unit =
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ sealed trait ConsoleOut {
|
|||
def print(s: String): Unit
|
||||
def println(s: String): Unit
|
||||
def println(): Unit
|
||||
def flush(): Unit
|
||||
}
|
||||
|
||||
object ConsoleOut {
|
||||
|
|
@ -39,6 +40,14 @@ object ConsoleOut {
|
|||
last = Some(s)
|
||||
current.setLength(0)
|
||||
}
|
||||
def flush(): Unit = synchronized {
|
||||
val s = current.toString
|
||||
if (ConsoleAppender.formatEnabledInEnv && last.exists(lmsg => f(s, lmsg)))
|
||||
lockObject.print(OverwriteLine)
|
||||
lockObject.print(s)
|
||||
last = Some(s)
|
||||
current.setLength(0)
|
||||
}
|
||||
}
|
||||
|
||||
def printStreamOut(out: PrintStream): ConsoleOut = new ConsoleOut {
|
||||
|
|
@ -46,17 +55,20 @@ object ConsoleOut {
|
|||
def print(s: String) = out.print(s)
|
||||
def println(s: String) = out.println(s)
|
||||
def println() = out.println()
|
||||
def flush() = out.flush()
|
||||
}
|
||||
def printWriterOut(out: PrintWriter): ConsoleOut = new ConsoleOut {
|
||||
val lockObject = out
|
||||
def print(s: String) = out.print(s)
|
||||
def println(s: String) = { out.println(s); out.flush() }
|
||||
def println() = { out.println(); out.flush() }
|
||||
def println(s: String) = { out.println(s); flush() }
|
||||
def println() = { out.println(); flush() }
|
||||
def flush() = { out.flush() }
|
||||
}
|
||||
def bufferedWriterOut(out: BufferedWriter): ConsoleOut = new ConsoleOut {
|
||||
val lockObject = out
|
||||
def print(s: String) = out.write(s)
|
||||
def println(s: String) = { out.write(s); println() }
|
||||
def println() = { out.newLine(); out.flush() }
|
||||
def println() = { out.newLine(); flush() }
|
||||
def flush() = { out.flush() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue