All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sbt.Highlight.scala Maven / Gradle / Ivy

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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy