@@ -138,26 +138,34 @@ trait CliCommand:
138
138
/** Used for the formatted output of -Xshow-phases */
139
139
protected def phasesMessage (using ctx : Context ): String =
140
140
141
+ import scala .io .AnsiColor .*
142
+ val colors = Array (GREEN , YELLOW , /* BLUE,*/ MAGENTA , CYAN , RED )
141
143
val phases = new Compiler ().phases
142
144
val nameLimit = 25
143
145
val maxCol = ctx.settings.pageWidth.value
144
146
val maxName = phases.flatten.map(_.phaseName.length).max
145
147
val width = maxName.min(nameLimit)
146
148
val maxDesc = maxCol - (width + 6 )
147
- val fmt = s " % ${width}. ${width}s %. ${maxDesc}s%n "
149
+ val colorSlot = if ctx.useColors then GREEN .length.toString else " 0"
150
+ val fmt = s " %. ${colorSlot}s% ${width}. ${width}s%. ${colorSlot}s %. ${maxDesc}s%n "
151
+ def plain (name : String , description : String ) = fmt.format(" " , name, " " , description)
148
152
149
153
val sb = new StringBuilder
150
- sb ++= fmt.format(" phase name" , " description" )
151
- sb ++= fmt.format(" ----------" , " -----------" )
152
-
153
- phases.foreach {
154
- case List (single) =>
155
- sb ++= fmt.format(single.phaseName, single.description)
156
- case Nil => ()
157
- case more =>
158
- sb ++= fmt.format(s " { " , " " )
159
- more.foreach { mini => sb ++= fmt.format(mini.phaseName, mini.description) }
160
- sb ++= fmt.format(s " } " , " " )
154
+ sb ++= plain(" phase name" , " description" )
155
+ sb ++= plain(" ----------" , " -----------" )
156
+
157
+ def color (index : Int ): String = colors(index % colors.length)
158
+ def emit (index : Int )(phase : core.Phases .Phase ): Unit = sb ++= fmt.format(color(index), phase.phaseName, RESET , phase.description)
159
+ def group (index : Int )(body : Int => Unit ): Unit =
160
+ if ! ctx.useColors then sb ++= plain(s " { " , " " )
161
+ body(index)
162
+ if ! ctx.useColors then sb ++= plain(s " } " , " " )
163
+
164
+ phases.zipWithIndex.foreach { (phase, index) =>
165
+ phase match
166
+ case List (single) => emit(index)(single)
167
+ case Nil =>
168
+ case mega => group(index)(i => mega.foreach(emit(i)))
161
169
}
162
170
sb.mkString
163
171
0 commit comments