Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not draw trailing whitespace #618

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.jakewharton.mosaic.ui.isNotEmptyTextStyle
import com.jakewharton.mosaic.ui.isSpecifiedColor
import com.jakewharton.mosaic.ui.isUnspecifiedColor
import de.cketti.codepoints.appendCodePoint
import kotlin.math.max

private val blankPixel = TextPixel(' ')

Expand All @@ -34,12 +35,14 @@ internal class TextSurface(
var translationY = 0

private val cells = Array(width * height) { TextPixel(' ') }
private val lastColumn = IntArray(height)

operator fun get(row: Int, column: Int): TextPixel {
val x = translationX + column
val y = row + translationY
check(x in 0 until width)
check(y in 0 until height)
lastColumn[y] = max(lastColumn[y], x + 1)
return cells[y * width + x]
}

Expand All @@ -50,7 +53,7 @@ internal class TextSurface(
var lastPixel = blankPixel

val rowStart = row * width
val rowStop = rowStart + width
val rowStop = rowStart + lastColumn[row]
for (columnIndex in rowStart until rowStop) {
val pixel = cells[columnIndex]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class AnsiRenderingTest {
}
}

// TODO We should not draw trailing whitespace.
assertThat(awaitSnapshot()).isEqualTo(
"""
|Hello$s
|Hello
|World!
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand All @@ -44,7 +43,7 @@ class AnsiRenderingTest {

assertThat(awaitSnapshot()).isEqualTo(
"""
|Hello$s
|Hello
|World!
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand All @@ -62,7 +61,7 @@ class AnsiRenderingTest {
assertThat(awaitSnapshot()).isEqualTo(
"""
|$cursorUp${cursorUp}Hel$clearLine
|lo $clearLine
|lo$clearLine
|Wor
|ld!
|
Expand All @@ -85,7 +84,7 @@ class AnsiRenderingTest {
assertThat(awaitSnapshot()).isEqualTo(
"""
|Hel
|lo$s
|lo
|Wor
|ld!
|
Expand All @@ -101,7 +100,7 @@ class AnsiRenderingTest {

assertThat(awaitSnapshot()).isEqualTo(
"""
|$cursorUp$cursorUp$cursorUp${cursorUp}Hello $clearLine
|$cursorUp$cursorUp$cursorUp${cursorUp}Hello$clearLine
|World!$clearLine
|$clearLine
|$clearLine$cursorUp
Expand Down Expand Up @@ -220,7 +219,7 @@ class AnsiRenderingTest {
"""
|Static
|TopTopTop
|LeftLeft$s
|LeftLeft
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CounterTest {
terminalState.value = Terminal(size = IntSize(width = 30, height = 1))
setCounterInTerminalCenter()
for (count in 0..9) {
assertThat(awaitSnapshot()).isEqualTo(" The count is: $count ")
assertThat(awaitSnapshot()).isEqualTo(" The count is: $count")
}

terminalState.value = Terminal(size = IntSize(width = 20, height = 1))
Expand All @@ -45,7 +45,7 @@ class CounterTest {
delay(250L)

for (count in 10..20) {
assertThat(awaitSnapshot()).isEqualTo(" The count is: $count ")
assertThat(awaitSnapshot()).isEqualTo(" The count is: $count")
}
}
}
Expand All @@ -60,7 +60,7 @@ class CounterTest {
for (count in 0..20) {
assertThat(awaitSnapshot()).isEqualTo(
"""
|The count is: $count $s
|The count is: $count
|The second count is: $count
""".trimMargin(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LayoutTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $s
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -99,8 +99,8 @@ class LayoutTest {
assertThat(awaitSnapshot()).isEqualTo(
"""
| CCC
| BB $s
|A $s
| BB
|A
""".trimMargin(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class MosaicTest {
}
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand Down Expand Up @@ -76,8 +76,8 @@ class MosaicTest {
}
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand Down Expand Up @@ -106,8 +106,8 @@ class MosaicTest {
}
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand Down Expand Up @@ -148,8 +148,8 @@ class MosaicTest {
}
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand All @@ -168,8 +168,8 @@ class MosaicTest {
}
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand All @@ -192,8 +192,8 @@ class MosaicTest {
actuals.forEach { actual ->
assertThat(actual).isEqualTo(
"""
|One $s
|Two $s
|One
|Two
|Three
|
""".trimMargin().wrapWithAnsiSynchronizedUpdate().replaceLineEndingsWithCRLF(),
Expand All @@ -216,8 +216,8 @@ class MosaicTest {
}
}

assertThat(awaitSnapshot()).isEqualTo("$TestChar ")
assertThat(awaitSnapshot()).isEqualTo(" $TestChar ")
assertThat(awaitSnapshot()).isEqualTo("$TestChar")
assertThat(awaitSnapshot()).isEqualTo(" $TestChar")
}
}

Expand All @@ -236,8 +236,8 @@ class MosaicTest {
}
}

assertThat(awaitSnapshot()).isEqualTo("$TestChar ")
assertThat(awaitSnapshot()).isEqualTo(" $TestChar ")
assertThat(awaitSnapshot()).isEqualTo("$TestChar")
assertThat(awaitSnapshot()).isEqualTo(" $TestChar")
}
}

Expand Down Expand Up @@ -266,8 +266,8 @@ class MosaicTest {
}
}

assertThat(awaitSnapshot()).isEqualTo("$TestChar ")
assertThat(awaitSnapshot()).isEqualTo("${TestChar + 1} ")
assertThat(awaitSnapshot()).isEqualTo("$TestChar")
assertThat(awaitSnapshot()).isEqualTo("${TestChar + 1}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.jakewharton.mosaic.TestChar
import com.jakewharton.mosaic.TestFiller
import com.jakewharton.mosaic.assertFailure
import com.jakewharton.mosaic.modifier.Modifier
import com.jakewharton.mosaic.s
import com.jakewharton.mosaic.testing.runMosaicTest
import com.jakewharton.mosaic.ui.Box
import com.jakewharton.mosaic.ui.unit.IntOffset
Expand All @@ -23,12 +22,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $TestChar $s
| $s
| $s
| $s
| $s
| $s
| $TestChar
|
|
|
|
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -71,12 +70,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $s
| $s
| $s
| $s
|$TestChar $s
| $s
|
|
|
|
|$TestChar
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -119,12 +118,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $s
| $s
| $s
| $s
| $TestChar $s
| $s
|
|
|
|
| $TestChar
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -172,12 +171,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $TestChar $s
| $s
| $s
| $s
| $s
| $s
| $TestChar
|
|
|
|
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -220,12 +219,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $s
| $s
| $s
| $s
|$TestChar $s
| $s
|
|
|
|
|$TestChar
|
""".trimMargin(),
)
}
Expand Down Expand Up @@ -268,12 +267,12 @@ class OffsetTest {
}
assertThat(awaitSnapshot()).isEqualTo(
"""
| $s
| $s
| $s
| $s
| $TestChar $s
| $s
|
|
|
|
| $TestChar
|
""".trimMargin(),
)
}
Expand Down
Loading