Skip to content

Commit b5baae1

Browse files
committed
Columnator accepts multiline field2
1 parent 9aba7d1 commit b5baae1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

compiler/src/dotty/tools/dotc/config/CliCommand.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,20 @@ trait CliCommand:
192192
val separator = " " * separation
193193
def formatField1(text: String): String = if text.length <= field1 then text.padLeft(field1) else EOL + "".padLeft(field1)
194194
def formatField2(text: String): String =
195-
if field2 == 0 || text.length <= field2 then text
196-
else
197-
text.lastIndexOf(" ", field2) match
198-
case -1 => text
199-
case i =>
200-
val (prefix, rest) = text.splitAt(i)
201-
s"${prefix}${EOL}${formatField1("")}${separator}${formatField2(rest.trim)}"
195+
def loopOverField2(fld: String): String =
196+
if field2 == 0 || fld.length <= field2 then fld
197+
else
198+
fld.lastIndexOf(" ", field2) match
199+
case -1 => fld
200+
case i =>
201+
val (prefix, rest) = fld.splitAt(i)
202+
s"${prefix}${EOL}${formatField1("")}${separator}${loopOverField2(rest.trim)}"
203+
def loopOverFields2(rest: List[String]): String =
204+
rest match
205+
case h :: t => loopOverField2(h.trim) + loopOverFields2(t)
206+
case Nil => ""
207+
loopOverFields2(text.split("\n").toList)
208+
end formatField2
202209
def format(first: String, second: String, index: Int, colorPicker: Int => String => Highlight) =
203210
sb.append(colorPicker(index)(formatField1(first)).show)
204211
.append(separator)

0 commit comments

Comments
 (0)