diff --git a/README.md b/README.md index 2488016..1a6c10e 100644 --- a/README.md +++ b/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 diff --git a/build.gradle.kts b/build.gradle.kts index d39c237..f08f4e6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,3 +28,15 @@ kotlin { application { mainClass.set("blitz.FnpKt") } + +publishing { + publications { + create("maven") { + groupId = group.toString() + artifactId = "blitz" + version = version.toString() + + from(components["kotlin"]) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/blitz/collections/Matrix.kt b/src/main/kotlin/blitz/collections/Matrix.kt index 4648fa8..e856fd9 100644 --- a/src/main/kotlin/blitz/collections/Matrix.kt +++ b/src/main/kotlin/blitz/collections/Matrix.kt @@ -58,13 +58,4 @@ class Matrix( rows.joinToString(separator = "\n") { 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()) } \ No newline at end of file diff --git a/src/main/kotlin/blitz/str/BoxDrawingCharSet.kt b/src/main/kotlin/blitz/str/BoxDrawingCharSet.kt new file mode 100644 index 0000000..33f5871 --- /dev/null +++ b/src/main/kotlin/blitz/str/BoxDrawingCharSet.kt @@ -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, end: Pair, 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: Pair, 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") } \ No newline at end of file diff --git a/src/main/kotlin/blitz/str/MutMultiLineString.kt b/src/main/kotlin/blitz/str/MutMultiLineString.kt index f2b5f59..250e2ee 100644 --- a/src/main/kotlin/blitz/str/MutMultiLineString.kt +++ b/src/main/kotlin/blitz/str/MutMultiLineString.kt @@ -64,6 +64,10 @@ class MutMultiLineString( } } + fun box(start: Pair, end: Pair, set: BoxDrawingCharSet) { + set.draw(start, end) { x, y, c -> this[y, x] = c } + } + override fun toString(): String = lines.joinToString(separator = "\n")