From 5be21a76476074ef89075fb204fab27b270722a9 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 8 Nov 2015 13:05:10 -0800 Subject: [PATCH] Center. --- src/main/kotlin/com/beust/kobalt/AsciiArt.kt | 10 ++++++++-- src/main/kotlin/com/beust/kobalt/ResolveDependency.kt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/src/main/kotlin/com/beust/kobalt/AsciiArt.kt index 15551b4e..00b75a80 100644 --- a/src/main/kotlin/com/beust/kobalt/AsciiArt.kt +++ b/src/main/kotlin/com/beust/kobalt/AsciiArt.kt @@ -42,7 +42,7 @@ class AsciiArt { val maxString: String = strings.maxBy { it.length } ?: "" val max = maxString.length val result = arrayListOf(ul + r(max + 2, h) + ur) - result.addAll(strings.map { "$v $it ${fill(max - it.length)}$v" }) + result.addAll(strings.map { "$v ${center(it, max - 2)} $v" }) result.add(bl + r(max + 2, h) + br) return result } @@ -58,7 +58,13 @@ class AsciiArt { } fun logBox(s: String, print: (String) -> Unit = defaultLog) { - logBox(listOf(s)) + logBox(listOf(s), print) + } + + fun center(s: String, width: Int) : String { + val diff = width - s.length + val spaces = diff / 2 + 1 + return fill(spaces) + s + fill(spaces + if (diff % 2 == 1) 1 else 0) } } } diff --git a/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index 204c09dd..3f5ba8bf 100644 --- a/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -27,7 +27,7 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) { val repoResult = repoFinder.findCorrectRepo(id) val simpleDep = SimpleDep(MavenId(id)) - val url = "Full URL: " + repoResult.repoUrl + simpleDep.toJarFile(repoResult) + val url = repoResult.repoUrl + simpleDep.toJarFile(repoResult) AsciiArt.logBox(listOf(id, url), {s -> println(s) }) display(root.children)