diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt index 000f3eee..6d8b78af 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt @@ -36,31 +36,42 @@ class AsciiArt { val horizontalSingleLine = "\u2500\u2500\u2500\u2500\u2500" val horizontalDoubleLine = "\u2550\u2550\u2550\u2550\u2550" + val verticalBar = "\u2551" // fun horizontalLine(n: Int) = StringBuffer().apply { // repeat(n, { append("\u2500") }) // }.toString() - fun box(strings: List) : List { - val ul = "\u2554" - val ur = "\u2557" - val h = "\u2550" - val v = "\u2551" - val bl = "\u255a" - val br = "\u255d" - - fun r(n: Int, w: String) : String { - with(StringBuffer()) { - repeat(n, { append(w) }) - return toString() - } + // Repeat + fun r(n: Int, w: String) : String { + with(StringBuffer()) { + repeat(n, { append(w) }) + return toString() } + } + + val h = "\u2550" + val ul = "\u2554" + val ur = "\u2557" + val bottomLeft = "\u255a" + val bottomRight = "\u255d" + + // Bottom left with continuation + val bottomLeft2 = "\u2560" + // Bottom right with continuation + val bottomRight2 = "\u2563" + + fun upperBox(max: Int) = ul + r(max + 2, h) + ur + fun lowerBox(max: Int, bl: String = bottomLeft, br : String = bottomRight) = bl + r(max + 2, h) + br + + private fun box(strings: List, bl: String = bottomLeft, br: String = bottomRight) : List { + val v = verticalBar val maxString: String = strings.maxBy { it.length } ?: "" val max = maxString.length - val result = arrayListOf(ul + r(max + 2, h) + ur) + val result = arrayListOf(upperBox(max)) result.addAll(strings.map { "$v ${center(it, max - 2)} $v" }) - result.add(bl + r(max + 2, h) + br) + result.add(lowerBox(max, bl, br)) return result } @@ -68,14 +79,15 @@ class AsciiArt { val defaultLog : (s: String) -> Unit = { log(1, " $it") } - fun logBox(strings: List, print: (String) -> Unit = defaultLog) { - box(strings).forEach { + fun logBox(strings: List, bl: String = bottomLeft, br: String = bottomRight, + print: (String) -> Unit = defaultLog) { + box(strings, bl, br).forEach { print(it) } } - fun logBox(s: String, print: (String) -> Unit = defaultLog) { - logBox(listOf(s), print) + fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, print: (String) -> Unit = defaultLog) { + logBox(listOf(s), bl, br, print) } fun center(s: String, width: Int) : String { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index 116e59e5..c81313d2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -42,7 +42,7 @@ class ResolveDependency @Inject constructor( val seen = hashSetOf(dep.id) root.addChildren(findChildren(root, seen)) - AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }, {s -> println(s) }) + AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }, print = {s -> println(s) }) display(root.children) println("") 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 5ca93797..96b6e10e 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 @@ -35,12 +35,19 @@ class BuildListeners : IBuildListener, IBuildReportContributor { } log(1, "\n") - log(1, "\n" + AsciiArt.horizontalSingleLine + " Build status") - projectStatuses.forEach { pair -> - log(1, " " + pair.first.name + " " + pair.second) - } } + fun col1(s: String) = String.format(" %1\$-30s", s) + fun col2(s: String) = String.format(" %1\$-10s", s) + + val line = listOf(col1("Project"), col2("Build status")).joinToString(AsciiArt.verticalBar) + AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2) + projectStatuses.forEach { pair -> + val cl = listOf(col1(pair.first.name), col2(pair.second.toString())).joinToString(AsciiArt.verticalBar) + log(1, " " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar) + } + log(1, " " + AsciiArt.lowerBox(line.length)) + }