Skip to content

Instantly share code, notes, and snippets.

@dsandler
Last active June 4, 2024 15:22
Show Gist options
  • Save dsandler/a638057381eb3bae4b28b1ed0adcaef8 to your computer and use it in GitHub Desktop.
Save dsandler/a638057381eb3bae4b28b1ed0adcaef8 to your computer and use it in GitHub Desktop.
val TEMPLATE = "┏━┓┃ ┃┗━┛".toCharArray().map { it.toString() }
val TEMPLATE2 = listOf("┌", "─", "┒",
"│", " ", "┃",
"┕", "━", "┛")
val TEMPLATE3 = listOf("┌─", "─", "─┒",
"│ ", " ", " ┃",
"┕━", "━", "━┛")
val ASCII = listOf(
"+-", "-", "-+",
"| ", " ", " |",
"+-", "-", "-+")
fun boxLines(lines: List<String>, template: List<String> = TEMPLATE): List<String> {
val maxLen = lines.maxOf { it.length }
val top = template[0] + template[1].repeat(maxLen) + template[2]
val bottom = template[6] + template[7].repeat(maxLen) + template[8]
val middleLines = lines.map {
template[3] + it + template[4].repeat(maxLen - it.length) + template[5]
}
return listOf(top) + middleLines + listOf(bottom)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment