From ffd641310d01d3aa4e85359aedd923fbe1777b83 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 9 Apr 2017 00:40:17 -0700 Subject: [PATCH] Format correctly. --- .../kotlin/com/beust/kobalt/internal/BuildListeners.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt index 9dbe042d..58d8eed8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt @@ -76,10 +76,15 @@ class BuildListeners : IBuildListener, IBuildReportContributor { } + // Calculate the longest short message so we can create a column long enough to contain it + val width = 12 + (projectInfos.values.map { it.shortMessage?.length ?: 0 }.maxBy { it } ?: 0) + fun col1(s: String) = String.format(" %1\$-30s", s) - fun col2(s: String) = String.format(" %1\$-13s", s) + fun col2(s: String) = String.format(" %1\$-${width}s", s) fun col3(s: String) = String.format(" %1\$-8s", s) + + // Only print the build report if there is more than one project and at least one of them failed if (timings.any()) { // if (timings.size > 1 && hasFailures) { @@ -89,7 +94,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor { table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10) + "\n") projectStatuses.forEach { pair -> val projectName = pair.first.name - val cl = listOf(col1(projectName), col2(pair.second.toString()), + val cl = listOf(col1(projectName), col2(pair.second), col3(formatMillisLeft(projectInfos[projectName]!!.durationMillis, 8))) .joinToString(AsciiArt.verticalBar) table.append(" " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar + "\n")