box drawing real
This commit is contained in:
16
README.md
16
README.md
@@ -12,7 +12,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("me.alex_s168:blitz:0.10")
|
||||
implementation("me.alex_s168:blitz:0.11")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -185,6 +185,20 @@ list.add(5)
|
||||
println(list.contents)
|
||||
// outputs: [1, 5, 9]
|
||||
```
|
||||
### Matrix
|
||||
```kotlin
|
||||
val mat = Matrix(3, 3) { x, y -> x * (3-y) }
|
||||
println(mat)
|
||||
println(mat.transposeCopy())
|
||||
println(mat.diagonals())
|
||||
```
|
||||
### Box drawing
|
||||
```kotlin
|
||||
val out = MutMultiColoredMultiLineString(fill = ColoredChar(' '))
|
||||
out.box(x to y, 20 to 5, BoxDrawingCharSet.ROUND, Terminal.COLORS.WHITE.brighter.fg)
|
||||
println(out.toString())
|
||||
```
|
||||
|
||||
### Either
|
||||
No example yet
|
||||
|
||||
|
@@ -28,3 +28,15 @@ kotlin {
|
||||
application {
|
||||
mainClass.set("blitz.FnpKt")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
groupId = group.toString()
|
||||
artifactId = "blitz"
|
||||
version = version.toString()
|
||||
|
||||
from(components["kotlin"])
|
||||
}
|
||||
}
|
||||
}
|
@@ -59,12 +59,3 @@ class Matrix<T>(
|
||||
it.joinToString(separator = ", ", prefix = "| ", postfix = " |")
|
||||
} + "\n--"
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val mat = Matrix(3, 3) { x, y -> x * (3-y) }
|
||||
println(mat)
|
||||
|
||||
println(mat.transposeCopy())
|
||||
|
||||
println(mat.diagonals())
|
||||
}
|
86
src/main/kotlin/blitz/str/BoxDrawingCharSet.kt
Normal file
86
src/main/kotlin/blitz/str/BoxDrawingCharSet.kt
Normal file
@@ -0,0 +1,86 @@
|
||||
package blitz.str
|
||||
|
||||
data class BoxDrawingCharSet(
|
||||
val cornerLeftTop: Char,
|
||||
val cornerRightTop: Char,
|
||||
val cornerLeftBottom: Char,
|
||||
val cornerRightBottom: Char,
|
||||
val horizontal: Char,
|
||||
val vertical: Char,
|
||||
) {
|
||||
constructor(corner: Char, horizontal: Char, vertical: Char): this(corner,corner,corner,corner,horizontal,vertical)
|
||||
constructor(corner: Char, line: Char): this(corner, line, line)
|
||||
constructor(all: Char): this(all, all)
|
||||
|
||||
/*
|
||||
0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
U+250x ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏
|
||||
|
||||
U+251x ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟
|
||||
|
||||
U+252x ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯
|
||||
|
||||
U+253x ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿
|
||||
|
||||
U+254x ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏
|
||||
|
||||
U+255x ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟
|
||||
|
||||
U+256x ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯
|
||||
|
||||
U+257x ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿
|
||||
*/
|
||||
|
||||
companion object {
|
||||
val ASCII = BoxDrawingCharSet('*', '-', '|')
|
||||
val ASCII_BOLD = BoxDrawingCharSet('#', '=', '|')
|
||||
val NORMAL = BoxDrawingCharSet('┌', '┐', '└', '┘', '─', '│')
|
||||
val BOLD = BoxDrawingCharSet('┏', '┓', '┗', '┛', '━', '┃')
|
||||
val BOLD_SPACED = BoxDrawingCharSet('┏', '┓', '┗', '┛', '╸', '╏')
|
||||
val DOUBLE = BoxDrawingCharSet('╔', '╗', '╚', '╝', '═', '║')
|
||||
val ROUND = BoxDrawingCharSet('╭', '╮', '╰', '╯', '─', '│')
|
||||
val DOTTED = BoxDrawingCharSet('┌', '┐', '└', '┘', '╴', '┆')
|
||||
val DOTTED_SMALL = BoxDrawingCharSet('┌', '┐', '└', '┘', '╴', '┊')
|
||||
val BOLD_DOTTED = BoxDrawingCharSet('┏', '┓', '┗', '┛', '╸', '┇')
|
||||
val BOLD_DOTTED_SMALL = BoxDrawingCharSet('┏', '┓', '┗', '┛', '╸', '┋')
|
||||
|
||||
val all = listOf(
|
||||
ASCII,
|
||||
ASCII_BOLD,
|
||||
NORMAL,
|
||||
BOLD,
|
||||
BOLD_SPACED,
|
||||
DOUBLE,
|
||||
ROUND,
|
||||
DOTTED,
|
||||
DOTTED_SMALL,
|
||||
BOLD_DOTTED,
|
||||
BOLD_DOTTED_SMALL,
|
||||
)
|
||||
}
|
||||
|
||||
fun draw(start: Pair<Int, Int>, end: Pair<Int, Int>, pixel: (x: Int, y: Int, c: Char) -> Unit) {
|
||||
pixel(start.first, start.second, cornerLeftTop)
|
||||
pixel(end.first, start.second, cornerRightTop)
|
||||
pixel(start.first, end.second, cornerLeftBottom)
|
||||
pixel(end.first, end.second, cornerRightBottom)
|
||||
|
||||
fun row(row: Int) {
|
||||
for (col in start.first+1..<end.first) {
|
||||
pixel(col, row, horizontal)
|
||||
}
|
||||
}
|
||||
|
||||
fun col(col: Int) {
|
||||
for (row in start.second+1..<end.second) {
|
||||
pixel(col, row, vertical)
|
||||
}
|
||||
}
|
||||
|
||||
row(start.second)
|
||||
row(end.second)
|
||||
|
||||
col(start.first)
|
||||
col(end.first)
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package blitz.str
|
||||
|
||||
import blitz.term.AnsiiMode
|
||||
import blitz.term.Terminal
|
||||
|
||||
class MutMultiColoredMultiLineString(
|
||||
var fill: ColoredChar
|
||||
@@ -104,6 +105,10 @@ class MutMultiColoredMultiLineString(
|
||||
}
|
||||
}
|
||||
|
||||
fun box(start: Pair<Int, Int>, end: Pair<Int, Int>, set: BoxDrawingCharSet, style: AnsiiMode = AnsiiMode(mutableListOf())) {
|
||||
set.draw(start, end) { x, y, c -> this[y, x] = ColoredChar(c, style) }
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
lines.joinToString(separator = "\n")
|
||||
}
|
@@ -64,6 +64,10 @@ class MutMultiLineString(
|
||||
}
|
||||
}
|
||||
|
||||
fun box(start: Pair<Int, Int>, end: Pair<Int, Int>, set: BoxDrawingCharSet) {
|
||||
set.draw(start, end) { x, y, c -> this[y, x] = c }
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
lines.joinToString(separator = "\n")
|
||||
|
||||
|
Reference in New Issue
Block a user