mirror of
https://github.com/JakeWharton/mosaic.git
synced 2025-11-01 20:20:19 +08:00
Share constants for ANSI control codes
This commit is contained in:
committed by
Jake Wharton
parent
3c18954fb0
commit
66eca84c5d
@ -0,0 +1,4 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
internal const val clearLine = "\u001B[K"
|
||||
internal const val cursorUp = "\u001B[F"
|
||||
@ -47,14 +47,14 @@ internal class AnsiRendering : Rendering {
|
||||
clear()
|
||||
|
||||
repeat(lastHeight) {
|
||||
append("\u001B[F") // Cursor up line.
|
||||
append(cursorUp)
|
||||
}
|
||||
|
||||
val staticLines = statics.flatMap { it.render().split("\n") }
|
||||
val lines = canvas.render().split("\n")
|
||||
for (line in staticLines + lines) {
|
||||
append(line)
|
||||
append("\u001B[K") // Clear rest of line.
|
||||
append(clearLine)
|
||||
append('\n')
|
||||
}
|
||||
|
||||
@ -64,12 +64,12 @@ internal class AnsiRendering : Rendering {
|
||||
if (i > 0) {
|
||||
append('\n')
|
||||
}
|
||||
append("\u001B[K") // Clear line.
|
||||
append(clearLine)
|
||||
}
|
||||
|
||||
// Move cursor back up to end of the new output.
|
||||
repeat(extraLines - 1) {
|
||||
append("\u001B[F") // Cursor up line.
|
||||
append(cursorUp)
|
||||
}
|
||||
|
||||
lastHeight = lines.size
|
||||
|
||||
@ -16,8 +16,8 @@ class AnsiRenderingTest {
|
||||
// TODO We should not draw trailing whitespace.
|
||||
assertEquals(
|
||||
"""
|
||||
|Hello $esc[K
|
||||
|World!$esc[K
|
||||
|Hello $clearLine
|
||||
|World!$clearLine
|
||||
|""".trimMargin(),
|
||||
rendering.render(helloCanvas).toString(),
|
||||
)
|
||||
|
||||
@ -13,9 +13,9 @@ class MosaicTest {
|
||||
}
|
||||
}
|
||||
assertEquals("""
|
||||
|One $esc[K
|
||||
|Two $esc[K
|
||||
|Three$esc[K
|
||||
|One $clearLine
|
||||
|Two $clearLine
|
||||
|Three$clearLine
|
||||
|""".trimMargin(), actual)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
internal const val esc = "\u001B"
|
||||
Reference in New Issue
Block a user