aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing/Highlighting.scala
blob: a496976a1e6a65a34dbc81ed79597a7d0bc7db72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package dotty.tools
package dotc
package printing

import scala.collection.mutable

object Highlighting {

  implicit def colorToString(c: Color): String = c.toString
  implicit def cbufToString(cb: ColorBuffer): String = cb.toString

  abstract class Color(private val color: String) {
    def text: String

    override def toString = color + text + Console.RESET

    def +(other: Color): ColorBuffer =
      new ColorBuffer(this) + other

    def +(other: String): ColorBuffer =
      new ColorBuffer(this) + other
  }

  case class ColorBuffer(color: Color) {
    val buffer = new mutable.ListBuffer[String]

    buffer += color.toString

    def +(color: Color): ColorBuffer = {
      buffer += color.toString
      this
    }

    def +(str: String): ColorBuffer = {
      buffer += str
      this
    }

    override def toString =
      buffer.mkString
  }

  case class Red(text: String) extends Color(Console.RED)
  case class Blue(text: String) extends Color(Console.BLUE)
  case class Cyan(text: String) extends Color(Console.CYAN)
  case class Black(text: String) extends Color(Console.BLACK)
  case class Green(text: String) extends Color(Console.GREEN)
  case class White(text: String) extends Color(Console.WHITE)
  case class Yellow(text: String) extends Color(Console.YELLOW)
  case class Magenta(text: String) extends Color(Console.MAGENTA)

  case class RedB(text: String) extends Color(Console.RED_B)
  case class BlueB(text: String) extends Color(Console.BLUE_B)
  case class CyanB(text: String) extends Color(Console.CYAN_B)
  case class BlackB(text: String) extends Color(Console.BLACK_B)
  case class GreenB(text: String) extends Color(Console.GREEN_B)
  case class WhiteB(text: String) extends Color(Console.WHITE_B)
  case class YellowB(text: String) extends Color(Console.YELLOW_B)
  case class MagentaB(text: String) extends Color(Console.MAGENTA_B)
}