Skip to content

Commit 313db47

Browse files
authored
Expose a public Mosaic type (#616)
1 parent 2ffbf43 commit 313db47

File tree

9 files changed

+151
-50
lines changed

9 files changed

+151
-50
lines changed

mosaic-runtime/api/mosaic-runtime.api

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
public abstract interface class com/jakewharton/mosaic/Mosaic {
2+
public abstract fun awaitComplete (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
3+
public abstract fun cancel ()V
4+
public abstract fun dump ()Ljava/lang/String;
5+
public abstract fun getTerminalState ()Landroidx/compose/runtime/MutableState;
6+
public abstract fun paint ()Lcom/jakewharton/mosaic/TextCanvas;
7+
public abstract fun paintStaticsTo (Landroidx/collection/MutableObjectList;)V
8+
public abstract fun sendKeyEvent (Lcom/jakewharton/mosaic/layout/KeyEvent;)V
9+
public abstract fun setContent (Lkotlin/jvm/functions/Function2;)V
10+
}
11+
112
public final class com/jakewharton/mosaic/MosaicKt {
13+
public static final fun Mosaic (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;)Lcom/jakewharton/mosaic/Mosaic;
214
public static final fun renderMosaic (Lkotlin/jvm/functions/Function2;)Ljava/lang/String;
315
public static final fun runMosaic (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
416
public static final fun runMosaicBlocking (Lkotlin/jvm/functions/Function2;)V
@@ -17,6 +29,13 @@ public final class com/jakewharton/mosaic/TerminalKt {
1729
public static final fun getLocalTerminal ()Landroidx/compose/runtime/ProvidableCompositionLocal;
1830
}
1931

32+
public abstract interface class com/jakewharton/mosaic/TextCanvas {
33+
public abstract fun appendRowTo (Ljava/lang/Appendable;ILcom/jakewharton/mosaic/ui/AnsiLevel;)V
34+
public abstract fun getHeight ()I
35+
public abstract fun getWidth ()I
36+
public abstract fun render (Lcom/jakewharton/mosaic/ui/AnsiLevel;)Ljava/lang/String;
37+
}
38+
2039
public final class com/jakewharton/mosaic/layout/AspectRatioKt {
2140
public static final fun aspectRatio (Lcom/jakewharton/mosaic/modifier/Modifier;FZ)Lcom/jakewharton/mosaic/modifier/Modifier;
2241
public static synthetic fun aspectRatio$default (Lcom/jakewharton/mosaic/modifier/Modifier;FZILjava/lang/Object;)Lcom/jakewharton/mosaic/modifier/Modifier;
@@ -368,6 +387,16 @@ public abstract interface class com/jakewharton/mosaic/ui/Alignment$Vertical {
368387
public abstract fun align (II)I
369388
}
370389

390+
public final class com/jakewharton/mosaic/ui/AnsiLevel : java/lang/Enum {
391+
public static final field ANSI16 Lcom/jakewharton/mosaic/ui/AnsiLevel;
392+
public static final field ANSI256 Lcom/jakewharton/mosaic/ui/AnsiLevel;
393+
public static final field NONE Lcom/jakewharton/mosaic/ui/AnsiLevel;
394+
public static final field TRUECOLOR Lcom/jakewharton/mosaic/ui/AnsiLevel;
395+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
396+
public static fun valueOf (Ljava/lang/String;)Lcom/jakewharton/mosaic/ui/AnsiLevel;
397+
public static fun values ()[Lcom/jakewharton/mosaic/ui/AnsiLevel;
398+
}
399+
371400
public final class com/jakewharton/mosaic/ui/Arrangement {
372401
public static final field $stable I
373402
public static final field INSTANCE Lcom/jakewharton/mosaic/ui/Arrangement;

mosaic-runtime/api/mosaic-runtime.klib.api

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ final enum class com.jakewharton.mosaic.layout/IntrinsicSize : kotlin/Enum<com.j
2525
final fun values(): kotlin/Array<com.jakewharton.mosaic.layout/IntrinsicSize> // com.jakewharton.mosaic.layout/IntrinsicSize.values|values#static(){}[0]
2626
}
2727

28+
final enum class com.jakewharton.mosaic.ui/AnsiLevel : kotlin/Enum<com.jakewharton.mosaic.ui/AnsiLevel> { // com.jakewharton.mosaic.ui/AnsiLevel|null[0]
29+
enum entry ANSI16 // com.jakewharton.mosaic.ui/AnsiLevel.ANSI16|null[0]
30+
enum entry ANSI256 // com.jakewharton.mosaic.ui/AnsiLevel.ANSI256|null[0]
31+
enum entry NONE // com.jakewharton.mosaic.ui/AnsiLevel.NONE|null[0]
32+
enum entry TRUECOLOR // com.jakewharton.mosaic.ui/AnsiLevel.TRUECOLOR|null[0]
33+
34+
final val entries // com.jakewharton.mosaic.ui/AnsiLevel.entries|#static{}entries[0]
35+
final fun <get-entries>(): kotlin.enums/EnumEntries<com.jakewharton.mosaic.ui/AnsiLevel> // com.jakewharton.mosaic.ui/AnsiLevel.entries.<get-entries>|<get-entries>#static(){}[0]
36+
37+
final fun valueOf(kotlin/String): com.jakewharton.mosaic.ui/AnsiLevel // com.jakewharton.mosaic.ui/AnsiLevel.valueOf|valueOf#static(kotlin.String){}[0]
38+
final fun values(): kotlin/Array<com.jakewharton.mosaic.ui/AnsiLevel> // com.jakewharton.mosaic.ui/AnsiLevel.values|values#static(){}[0]
39+
}
40+
2841
abstract fun interface com.jakewharton.mosaic.layout/MeasurePolicy { // com.jakewharton.mosaic.layout/MeasurePolicy|null[0]
2942
abstract fun (com.jakewharton.mosaic.layout/MeasureScope).measure(kotlin.collections/List<com.jakewharton.mosaic.layout/Measurable>, com.jakewharton.mosaic.ui.unit/Constraints): com.jakewharton.mosaic.layout/MeasureResult // com.jakewharton.mosaic.layout/MeasurePolicy.measure|[email protected](kotlin.collections.List<com.jakewharton.mosaic.layout.Measurable>;com.jakewharton.mosaic.ui.unit.Constraints){}[0]
3043
open fun maxIntrinsicHeight(kotlin.collections/List<com.jakewharton.mosaic.layout/IntrinsicMeasurable>, kotlin/Int): kotlin/Int // com.jakewharton.mosaic.layout/MeasurePolicy.maxIntrinsicHeight|maxIntrinsicHeight(kotlin.collections.List<com.jakewharton.mosaic.layout.IntrinsicMeasurable>;kotlin.Int){}[0]
@@ -183,6 +196,29 @@ abstract interface com.jakewharton.mosaic.ui/RowScope { // com.jakewharton.mosai
183196
abstract fun (com.jakewharton.mosaic.modifier/Modifier).weight(kotlin/Float, kotlin/Boolean = ...): com.jakewharton.mosaic.modifier/Modifier // com.jakewharton.mosaic.ui/RowScope.weight|[email protected](kotlin.Float;kotlin.Boolean){}[0]
184197
}
185198

199+
abstract interface com.jakewharton.mosaic/Mosaic { // com.jakewharton.mosaic/Mosaic|null[0]
200+
abstract val terminalState // com.jakewharton.mosaic/Mosaic.terminalState|{}terminalState[0]
201+
abstract fun <get-terminalState>(): androidx.compose.runtime/MutableState<com.jakewharton.mosaic/Terminal> // com.jakewharton.mosaic/Mosaic.terminalState.<get-terminalState>|<get-terminalState>(){}[0]
202+
203+
abstract fun cancel() // com.jakewharton.mosaic/Mosaic.cancel|cancel(){}[0]
204+
abstract fun dump(): kotlin/String // com.jakewharton.mosaic/Mosaic.dump|dump(){}[0]
205+
abstract fun paint(): com.jakewharton.mosaic/TextCanvas // com.jakewharton.mosaic/Mosaic.paint|paint(){}[0]
206+
abstract fun paintStaticsTo(androidx.collection/MutableObjectList<com.jakewharton.mosaic/TextCanvas>) // com.jakewharton.mosaic/Mosaic.paintStaticsTo|paintStaticsTo(androidx.collection.MutableObjectList<com.jakewharton.mosaic.TextCanvas>){}[0]
207+
abstract fun sendKeyEvent(com.jakewharton.mosaic.layout/KeyEvent) // com.jakewharton.mosaic/Mosaic.sendKeyEvent|sendKeyEvent(com.jakewharton.mosaic.layout.KeyEvent){}[0]
208+
abstract fun setContent(kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>) // com.jakewharton.mosaic/Mosaic.setContent|setContent(kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>){}[0]
209+
abstract suspend fun awaitComplete() // com.jakewharton.mosaic/Mosaic.awaitComplete|awaitComplete(){}[0]
210+
}
211+
212+
abstract interface com.jakewharton.mosaic/TextCanvas { // com.jakewharton.mosaic/TextCanvas|null[0]
213+
abstract val height // com.jakewharton.mosaic/TextCanvas.height|{}height[0]
214+
abstract fun <get-height>(): kotlin/Int // com.jakewharton.mosaic/TextCanvas.height.<get-height>|<get-height>(){}[0]
215+
abstract val width // com.jakewharton.mosaic/TextCanvas.width|{}width[0]
216+
abstract fun <get-width>(): kotlin/Int // com.jakewharton.mosaic/TextCanvas.width.<get-width>|<get-width>(){}[0]
217+
218+
abstract fun appendRowTo(kotlin.text/Appendable, kotlin/Int, com.jakewharton.mosaic.ui/AnsiLevel) // com.jakewharton.mosaic/TextCanvas.appendRowTo|appendRowTo(kotlin.text.Appendable;kotlin.Int;com.jakewharton.mosaic.ui.AnsiLevel){}[0]
219+
abstract fun render(com.jakewharton.mosaic.ui/AnsiLevel): kotlin/String // com.jakewharton.mosaic/TextCanvas.render|render(com.jakewharton.mosaic.ui.AnsiLevel){}[0]
220+
}
221+
186222
sealed interface com.jakewharton.mosaic.layout/DrawStyle { // com.jakewharton.mosaic.layout/DrawStyle|null[0]
187223
final class Stroke : com.jakewharton.mosaic.layout/DrawStyle { // com.jakewharton.mosaic.layout/DrawStyle.Stroke|null[0]
188224
constructor <init>(kotlin/Int = ...) // com.jakewharton.mosaic.layout/DrawStyle.Stroke.<init>|<init>(kotlin.Int){}[0]
@@ -752,6 +788,7 @@ final fun com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_RowColumnMeasureme
752788
final fun com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_RowColumnParentData$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_RowColumnParentData$stableprop_getter|com_jakewharton_mosaic_ui_RowColumnParentData$stableprop_getter(){}[0]
753789
final fun com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_RowScopeInstance$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_RowScopeInstance$stableprop_getter|com_jakewharton_mosaic_ui_RowScopeInstance$stableprop_getter(){}[0]
754790
final fun com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_VerticalAlignModifier$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic.ui/com_jakewharton_mosaic_ui_VerticalAlignModifier$stableprop_getter|com_jakewharton_mosaic_ui_VerticalAlignModifier$stableprop_getter(){}[0]
791+
final fun com.jakewharton.mosaic/Mosaic(kotlin.coroutines/CoroutineContext, kotlin/Function1<com.jakewharton.mosaic/Mosaic, kotlin/Unit>): com.jakewharton.mosaic/Mosaic // com.jakewharton.mosaic/Mosaic|Mosaic(kotlin.coroutines.CoroutineContext;kotlin.Function1<com.jakewharton.mosaic.Mosaic,kotlin.Unit>){}[0]
755792
final fun com.jakewharton.mosaic/com_jakewharton_mosaic_AnsiRendering$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic/com_jakewharton_mosaic_AnsiRendering$stableprop_getter|com_jakewharton_mosaic_AnsiRendering$stableprop_getter(){}[0]
756793
final fun com.jakewharton.mosaic/com_jakewharton_mosaic_DebugRendering$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic/com_jakewharton_mosaic_DebugRendering$stableprop_getter|com_jakewharton_mosaic_DebugRendering$stableprop_getter(){}[0]
757794
final fun com.jakewharton.mosaic/com_jakewharton_mosaic_GlobalSnapshotManager$stableprop_getter(): kotlin/Int // com.jakewharton.mosaic/com_jakewharton_mosaic_GlobalSnapshotManager$stableprop_getter|com_jakewharton_mosaic_GlobalSnapshotManager$stableprop_getter(){}[0]

mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/layout/Node.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jakewharton.mosaic.layout
22

33
import androidx.collection.MutableObjectList
4+
import com.jakewharton.mosaic.TextCanvas
45
import com.jakewharton.mosaic.TextSurface
56
import com.jakewharton.mosaic.layout.Placeable.PlacementScope
67
import com.jakewharton.mosaic.modifier.Modifier
@@ -139,7 +140,7 @@ internal class MosaicNode(
139140
* Draw this node to a [TextSurface].
140141
* A call to [measureAndPlace] must precede calls to this function.
141142
*/
142-
fun paint(): TextSurface {
143+
fun paint(): TextCanvas {
143144
val surface = TextSurface(width, height)
144145
topLayer.drawTo(surface)
145146
return surface
@@ -149,7 +150,7 @@ internal class MosaicNode(
149150
* Append any static [TextSurfaces][TextSurface] to [statics].
150151
* A call to [measureAndPlace] must precede calls to this function.
151152
*/
152-
fun paintStaticsTo(statics: MutableObjectList<TextSurface>) {
153+
fun paintStaticsTo(statics: MutableObjectList<TextCanvas>) {
153154
for (index in children.indices) {
154155
val child = children[index]
155156
if (isStatic) {

mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/mosaic.kt

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
88
import androidx.compose.runtime.Composition
99
import androidx.compose.runtime.CompositionLocalProvider
1010
import androidx.compose.runtime.MonotonicFrameClock
11+
import androidx.compose.runtime.MutableState
1112
import androidx.compose.runtime.Recomposer
1213
import androidx.compose.runtime.mutableStateOf
1314
import androidx.compose.runtime.snapshots.ObserverHandle
@@ -124,7 +125,7 @@ private fun createRendering(ansiLevel: AnsiLevel = AnsiLevel.TRUECOLOR): Renderi
124125
}
125126
}
126127

127-
private fun CoroutineScope.updateTerminalInfo(terminal: MordantTerminal, mosaic: MosaicComposition) {
128+
private fun CoroutineScope.updateTerminalInfo(terminal: MordantTerminal, mosaic: Mosaic) {
128129
launch(start = UNDISPATCHED) {
129130
while (true) {
130131
val currentTerminalInfo = mosaic.terminalState.value
@@ -139,7 +140,7 @@ private fun CoroutineScope.updateTerminalInfo(terminal: MordantTerminal, mosaic:
139140
}
140141
}
141142

142-
private fun CoroutineScope.readRawModeKeys(rawMode: RawModeScope, mosaic: MosaicComposition) {
143+
private fun CoroutineScope.readRawModeKeys(rawMode: RawModeScope, mosaic: Mosaic) {
143144
launch(Dispatchers.IO) {
144145
while (isActive) {
145146
val keyboardEvent = rawMode.readKeyOrNull(10.milliseconds) ?: continue
@@ -154,14 +155,27 @@ private fun CoroutineScope.readRawModeKeys(rawMode: RawModeScope, mosaic: Mosaic
154155
}
155156
}
156157

157-
internal interface Mosaic {
158-
fun paint(): TextSurface
159-
fun paintStaticsTo(list: MutableObjectList<TextSurface>)
160-
fun dump(): String
158+
public interface Mosaic {
159+
public fun setContent(content: @Composable () -> Unit)
160+
161+
public fun sendKeyEvent(keyEvent: KeyEvent)
162+
public val terminalState: MutableState<Terminal>
163+
164+
public fun paint(): TextCanvas
165+
public fun paintStaticsTo(list: MutableObjectList<TextCanvas>)
166+
public fun dump(): String
167+
168+
public suspend fun awaitComplete()
169+
public fun cancel()
161170
}
162171

163-
// https://en.wikipedia.org/wiki/VT52
164-
private val DefaultTestTerminalSize = IntSize(width = 80, height = 24)
172+
// TODO This function signature is all kinds of broken for structured concurrency!
173+
public fun Mosaic(
174+
coroutineContext: CoroutineContext,
175+
onDraw: (Mosaic) -> Unit,
176+
): Mosaic {
177+
return MosaicComposition(coroutineContext, onDraw)
178+
}
165179

166180
internal class MosaicComposition(
167181
coroutineContext: CoroutineContext,
@@ -177,7 +191,7 @@ internal class MosaicComposition(
177191
val scope = CoroutineScope(composeContext)
178192

179193
private val keyEvents = Channel<KeyEvent>(UNLIMITED)
180-
val terminalState = mutableStateOf(Terminal(DefaultTestTerminalSize))
194+
override val terminalState = mutableStateOf(Terminal(DefaultTestTerminalSize))
181195

182196
private val applier = MosaicNodeApplier { needLayout = true }
183197
val rootNode = applier.root
@@ -218,13 +232,13 @@ internal class MosaicComposition(
218232
onDraw(this)
219233
}
220234

221-
override fun paint(): TextSurface {
235+
override fun paint(): TextCanvas {
222236
return Snapshot.observe(readObserver = drawBlockStateReadObserver) {
223237
rootNode.paint()
224238
}
225239
}
226240

227-
override fun paintStaticsTo(list: MutableObjectList<TextSurface>) {
241+
override fun paintStaticsTo(list: MutableObjectList<TextCanvas>) {
228242
rootNode.paintStaticsTo(list)
229243
}
230244

@@ -287,7 +301,7 @@ internal class MosaicComposition(
287301
}
288302
}
289303

290-
fun setContent(content: @Composable () -> Unit) {
304+
override fun setContent(content: @Composable () -> Unit) {
291305
composition.setContent {
292306
CompositionLocalProvider(
293307
LocalTerminal provides terminalState.value,
@@ -297,11 +311,11 @@ internal class MosaicComposition(
297311
performLayout()
298312
}
299313

300-
fun sendKeyEvent(keyEvent: KeyEvent) {
314+
override fun sendKeyEvent(keyEvent: KeyEvent) {
301315
keyEvents.trySend(keyEvent)
302316
}
303317

304-
suspend fun awaitComplete() {
318+
override suspend fun awaitComplete() {
305319
try {
306320
val effectJob = checkNotNull(recomposer.effectCoroutineContext[Job]) {
307321
"No Job in effectCoroutineContext of recomposer"
@@ -322,7 +336,7 @@ internal class MosaicComposition(
322336
}
323337
}
324338

325-
fun cancel() {
339+
override fun cancel() {
326340
applyObserverHandle.dispose()
327341
recomposer.cancel()
328342
job.cancel()
@@ -333,6 +347,9 @@ internal class MosaicComposition(
333347
}
334348
}
335349

350+
// https://en.wikipedia.org/wiki/VT52
351+
private val DefaultTestTerminalSize = IntSize(width = 80, height = 24)
352+
336353
internal class MosaicNodeApplier(
337354
private val onChanges: () -> Unit = {},
338355
) : AbstractApplier<MosaicNode>(

mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/rendering.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class DebugRendering(
3535
appendLine(mosaic.dump())
3636
appendLine()
3737

38-
val statics = mutableObjectListOf<TextSurface>()
38+
val statics = mutableObjectListOf<TextCanvas>()
3939
try {
4040
mosaic.paintStaticsTo(statics)
4141
if (statics.isNotEmpty()) {
@@ -69,7 +69,7 @@ internal class AnsiRendering(
6969
private val ansiLevel: AnsiLevel = AnsiLevel.TRUECOLOR,
7070
) : Rendering {
7171
private val stringBuilder = StringBuilder(100)
72-
private val staticSurfaces = mutableObjectListOf<TextSurface>()
72+
private val staticSurfaces = mutableObjectListOf<TextCanvas>()
7373
private var lastHeight = 0
7474

7575
override fun render(mosaic: Mosaic): CharSequence {
@@ -83,7 +83,7 @@ internal class AnsiRendering(
8383
append(cursorUp)
8484
}
8585

86-
fun appendSurface(canvas: TextSurface) {
86+
fun appendSurface(canvas: TextCanvas) {
8787
for (row in 0 until canvas.height) {
8888
canvas.appendRowTo(this, row, ansiLevel)
8989
if (staleLines-- > 0) {

mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/surface.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ import de.cketti.codepoints.appendCodePoint
1818

1919
private val blankPixel = TextPixel(' ')
2020

21+
public interface TextCanvas {
22+
public val height: Int
23+
public val width: Int
24+
25+
public fun render(ansiLevel: AnsiLevel): String
26+
public fun appendRowTo(appendable: Appendable, row: Int, ansiLevel: AnsiLevel)
27+
}
28+
2129
internal class TextSurface(
22-
val width: Int,
23-
val height: Int,
24-
) {
30+
override val width: Int,
31+
override val height: Int,
32+
) : TextCanvas {
2533
var translationX = 0
2634
var translationY = 0
2735

@@ -35,7 +43,7 @@ internal class TextSurface(
3543
return cells[y * width + x]
3644
}
3745

38-
fun appendRowTo(appendable: Appendable, row: Int, ansiLevel: AnsiLevel) {
46+
override fun appendRowTo(appendable: Appendable, row: Int, ansiLevel: AnsiLevel) {
3947
// Reused heap allocation for building ANSI attributes inside the loop.
4048
val attributes = mutableIntListOf()
4149

@@ -145,7 +153,7 @@ internal class TextSurface(
145153
}
146154
}
147155

148-
fun render(ansiLevel: AnsiLevel): String = buildString {
156+
override fun render(ansiLevel: AnsiLevel): String = buildString {
149157
if (height > 0) {
150158
for (rowIndex in 0 until height) {
151159
appendRowTo(this, rowIndex, ansiLevel)

mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/ui/AnsiLevel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.jakewharton.mosaic.ui
22

3-
internal enum class AnsiLevel {
3+
public enum class AnsiLevel {
44
NONE,
55
ANSI16,
66
ANSI256,

mosaic-runtime/src/commonTest/kotlin/com/jakewharton/mosaic/CounterTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.jakewharton.mosaic.ui.Alignment
1313
import com.jakewharton.mosaic.ui.Box
1414
import com.jakewharton.mosaic.ui.Column
1515
import com.jakewharton.mosaic.ui.Text
16+
import com.jakewharton.mosaic.ui.unit.IntSize
1617
import kotlin.test.Test
1718
import kotlinx.coroutines.delay
1819
import kotlinx.coroutines.test.runTest
@@ -29,13 +30,13 @@ class CounterTest {
2930

3031
@Test fun counterInTerminalCenter() = runTest {
3132
runMosaicTest {
32-
setTerminalSize(width = 30, height = 1)
33+
terminalState.value = Terminal(size = IntSize(width = 30, height = 1))
3334
setCounterInTerminalCenter()
3435
for (count in 0..9) {
3536
assertThat(awaitSnapshot()).isEqualTo(" The count is: $count ")
3637
}
3738

38-
setTerminalSize(width = 20, height = 1)
39+
terminalState.value = Terminal(size = IntSize(width = 20, height = 1))
3940

4041
// After changing the terminal size, we wait for the counter to increase before getting a
4142
// new snapshot, otherwise there will be the previous value (9) and a different output size.

0 commit comments

Comments
 (0)