@@ -138,11 +138,32 @@ trait CliCommand:
138138 protected def yusageMessage (using settings : ConcreteSettings )(using SettingsState ) =
139139 createUsageMsg(" Possible private" , shouldExplain = true , isPrivate)
140140
141- protected def phasesMessage : String =
142- (new Compiler ()).phases.map {
143- case List (single) => single.phaseName
144- case more => more.map(_.phaseName).mkString(" {" , " , " , " }" )
145- }.mkString(" \n " )
141+ /** Used for the formatted output of -Xshow-phases */
142+ protected def phasesMessage (using ctx : Context ): String =
143+
144+ val phases = new Compiler ().phases
145+ val nameLimit = 25
146+ val maxCol = ctx.settings.pageWidth.value
147+ val maxName = phases.flatten.map(_.phaseName.length).max
148+ val width = maxName.min(nameLimit)
149+ val maxDesc = maxCol - (width + 6 )
150+ val fmt = s " % ${width}. ${width}s %. ${maxDesc}s%n "
151+
152+ 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 " } " , " " )
164+ }
165+ sb.mkString
166+
146167
147168 /** Provide usage feedback on argument summary, assuming that all settings
148169 * are already applied in context.
0 commit comments