mirror of
https://github.com/JakeWharton/mosaic.git
synced 2025-11-03 22:08:43 +08:00
Use CLRF line endings to support rendering in raw mode (#337)
* Use CRLF line endings to support rendering when terminal runs in raw mode * Update tests to expect CRLF line endings * Update CHANGELOG.md * Update CHANGELOG.md * Apply changes from spotlessKotlin --------- Co-authored-by: Jake Wharton <github@jakewharton.com>
This commit is contained in:
@ -9,7 +9,7 @@ Changed:
|
|||||||
- Disable klib signature clash checks for JS compilations. These occasionally occur as a result of Compose compiler behavior, and are safe to disable (the first-party JetBrains Compose Gradle plugin also disables them).
|
- Disable klib signature clash checks for JS compilations. These occasionally occur as a result of Compose compiler behavior, and are safe to disable (the first-party JetBrains Compose Gradle plugin also disables them).
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
-
|
- Use CRLF line endings to fix rendering when a terminal is in raw mode.
|
||||||
|
|
||||||
|
|
||||||
## [0.11.0] - 2023-02-27
|
## [0.11.0] - 2023-02-27
|
||||||
|
|||||||
@ -84,7 +84,7 @@ internal class TextSurface(
|
|||||||
fun render(): String = buildString {
|
fun render(): String = buildString {
|
||||||
for (rowIndex in 0 until height) {
|
for (rowIndex in 0 until height) {
|
||||||
if (rowIndex > 0) {
|
if (rowIndex > 0) {
|
||||||
append('\n')
|
append("\r\n")
|
||||||
}
|
}
|
||||||
appendRowTo(this, rowIndex)
|
appendRowTo(this, rowIndex)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,7 +89,7 @@ internal class AnsiRendering : Rendering {
|
|||||||
// We have previously drawn on this line. Clear the rest to be safe.
|
// We have previously drawn on this line. Clear the rest to be safe.
|
||||||
append(clearLine)
|
append(clearLine)
|
||||||
}
|
}
|
||||||
append('\n')
|
append("\r\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ internal class AnsiRendering : Rendering {
|
|||||||
// If the new output contains fewer lines than the last output, clear those old lines.
|
// If the new output contains fewer lines than the last output, clear those old lines.
|
||||||
for (i in 0 until staleLines) {
|
for (i in 0 until staleLines) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
append('\n')
|
append("\r\n")
|
||||||
}
|
}
|
||||||
append(clearLine)
|
append(clearLine)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class AnsiRenderingTest {
|
|||||||
|Hello$s
|
|Hello$s
|
||||||
|World!
|
|World!
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class AnsiRenderingTest {
|
|||||||
|Hello$s
|
|Hello$s
|
||||||
|World!
|
|World!
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val second = mosaicNodes {
|
val second = mosaicNodes {
|
||||||
@ -61,7 +61,7 @@ class AnsiRenderingTest {
|
|||||||
|Wor
|
|Wor
|
||||||
|ld!
|
|ld!
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class AnsiRenderingTest {
|
|||||||
|Wor
|
|Wor
|
||||||
|ld!
|
|ld!
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val second = mosaicNodes {
|
val second = mosaicNodes {
|
||||||
@ -98,7 +98,7 @@ class AnsiRenderingTest {
|
|||||||
|World!$clearLine
|
|World!$clearLine
|
||||||
|$clearLine
|
|$clearLine
|
||||||
|$clearLine$cursorUp
|
|$clearLine$cursorUp
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class AnsiRenderingTest {
|
|||||||
|World!
|
|World!
|
||||||
|Hello
|
|Hello
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class AnsiRenderingTest {
|
|||||||
|One
|
|One
|
||||||
|Two
|
|Two
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val second = mosaicNodes {
|
val second = mosaicNodes {
|
||||||
@ -147,7 +147,7 @@ class AnsiRenderingTest {
|
|||||||
|${cursorUp}Three$clearLine
|
|${cursorUp}Three$clearLine
|
||||||
|Four
|
|Four
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ class AnsiRenderingTest {
|
|||||||
|Five
|
|Five
|
||||||
|Sup
|
|Sup
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ class AnsiRenderingTest {
|
|||||||
|TopTopTop
|
|TopTopTop
|
||||||
|LeftLeft$s
|
|LeftLeft$s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ class LayoutTest {
|
|||||||
val expected = """
|
val expected = """
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin().replaceLineEndingsWithCRLF()
|
||||||
assertThat(actual).isEqualTo(expected)
|
assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class LayoutTest {
|
|||||||
val expected = """
|
val expected = """
|
||||||
|ABC
|
|ABC
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin().replaceLineEndingsWithCRLF()
|
||||||
assertThat(actual).isEqualTo(expected)
|
assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class LayoutTest {
|
|||||||
| BB $s
|
| BB $s
|
||||||
|A $s
|
|A $s
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin().replaceLineEndingsWithCRLF()
|
||||||
assertThat(actual).isEqualTo(expected)
|
assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ class LayoutTest {
|
|||||||
|...XXX
|
|...XXX
|
||||||
|.....X
|
|.....X
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin().replaceLineEndingsWithCRLF()
|
||||||
assertThat(actual).isEqualTo(expected)
|
assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class MosaicTest {
|
|||||||
|Two $s
|
|Two $s
|
||||||
|Three
|
|Three
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.jakewharton.mosaic.TestChar
|
|||||||
import com.jakewharton.mosaic.TestFiller
|
import com.jakewharton.mosaic.TestFiller
|
||||||
import com.jakewharton.mosaic.modifier.Modifier
|
import com.jakewharton.mosaic.modifier.Modifier
|
||||||
import com.jakewharton.mosaic.renderMosaic
|
import com.jakewharton.mosaic.renderMosaic
|
||||||
|
import com.jakewharton.mosaic.replaceLineEndingsWithCRLF
|
||||||
import com.jakewharton.mosaic.s
|
import com.jakewharton.mosaic.s
|
||||||
import com.jakewharton.mosaic.ui.Box
|
import com.jakewharton.mosaic.ui.Box
|
||||||
import com.jakewharton.mosaic.ui.unit.IntOffset
|
import com.jakewharton.mosaic.ui.unit.IntOffset
|
||||||
@ -28,7 +29,7 @@ class OffsetTest {
|
|||||||
| $s
|
| $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ class OffsetTest {
|
|||||||
|$TestChar $s
|
|$TestChar $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ class OffsetTest {
|
|||||||
| $TestChar $s
|
| $TestChar $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ class OffsetTest {
|
|||||||
| $s
|
| $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ class OffsetTest {
|
|||||||
|$TestChar $s
|
|$TestChar $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +229,7 @@ class OffsetTest {
|
|||||||
| $TestChar $s
|
| $TestChar $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import com.jakewharton.mosaic.TestChar
|
|||||||
import com.jakewharton.mosaic.TestFiller
|
import com.jakewharton.mosaic.TestFiller
|
||||||
import com.jakewharton.mosaic.modifier.Modifier
|
import com.jakewharton.mosaic.modifier.Modifier
|
||||||
import com.jakewharton.mosaic.renderMosaic
|
import com.jakewharton.mosaic.renderMosaic
|
||||||
|
import com.jakewharton.mosaic.replaceLineEndingsWithCRLF
|
||||||
import com.jakewharton.mosaic.s
|
import com.jakewharton.mosaic.s
|
||||||
import com.jakewharton.mosaic.testIntrinsics
|
import com.jakewharton.mosaic.testIntrinsics
|
||||||
import com.jakewharton.mosaic.ui.Layout
|
import com.jakewharton.mosaic.ui.Layout
|
||||||
@ -40,7 +41,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
| $TestChar
|
| $TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class PaddingTest {
|
|||||||
|$s
|
|$s
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar $s
|
|$TestChar $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +148,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ class PaddingTest {
|
|||||||
|$s
|
|$s
|
||||||
|$s
|
|$s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +185,7 @@ class PaddingTest {
|
|||||||
"""
|
"""
|
||||||
|$TestChar
|
|$TestChar
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +199,7 @@ class PaddingTest {
|
|||||||
| $s
|
| $s
|
||||||
| $s
|
| $s
|
||||||
|
|
|
|
||||||
""".trimMargin(),
|
""".trimMargin().replaceLineEndingsWithCRLF(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,10 @@ const val s = " "
|
|||||||
|
|
||||||
const val TestChar = 'X'
|
const val TestChar = 'X'
|
||||||
|
|
||||||
|
fun String.replaceLineEndingsWithCRLF(): String {
|
||||||
|
return this.replace("\n", "\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
fun <T> snapshotStateListOf(vararg values: T): SnapshotStateList<T> {
|
fun <T> snapshotStateListOf(vararg values: T): SnapshotStateList<T> {
|
||||||
return SnapshotStateList<T>().apply { addAll(values) }
|
return SnapshotStateList<T>().apply { addAll(values) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user