sbt.Highlight.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of command_2.12 Show documentation
Show all versions of command_2.12 Show documentation
sbt is an interactive build tool
The newest version!
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt
import java.util.regex.Pattern
import scala.Console.{ BOLD, RESET }
import sbt.internal.util.{ Terminal => UTerminal }
object Highlight {
def showMatches(pattern: Pattern)(line: String): Option[String] = {
val matcher = pattern.matcher(line)
if (UTerminal.isColorEnabled) {
// ANSI codes like \033[39m (normal text color) don't work on Windows
val highlighted = matcher.replaceAll(scala.Console.RED + "$0" + RESET)
if (highlighted == line) None else Some(highlighted)
} else if (matcher.find)
Some(line)
else
None
}
def bold(s: String) =
if (UTerminal.isColorEnabled) BOLD + s.replace(RESET, RESET + BOLD) + RESET else s
}