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