Skip to content

Commit

Permalink
Support annotated strings for static logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mattprecious committed Dec 28, 2024
1 parent cd6857e commit 9464924
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.remember
import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.jakewharton.mosaic.runMosaicBlocking
import com.jakewharton.mosaic.text.AnnotatedString
import com.mattprecious.stacker.config.ConfigManager
import com.mattprecious.stacker.lock.Locker
import com.mattprecious.stacker.rendering.LocalPrinter
Expand Down Expand Up @@ -91,6 +92,10 @@ internal abstract class StackerCommand(
printer.printStatic(message)
}

fun printStatic(message: AnnotatedString) {
printer.printStatic(message)
}

suspend fun <R> render(content: @Composable (onResult: (R) -> Unit) -> Unit): R {
state.value = State.Rendering(content)
return state.filterIsInstance<State.DeliveringRenderResult<R>>().first().result.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package com.mattprecious.stacker.rendering
import androidx.compose.runtime.Composable
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.staticCompositionLocalOf
import com.jakewharton.mosaic.text.AnnotatedString
import com.jakewharton.mosaic.text.buildAnnotatedString
import com.jakewharton.mosaic.ui.Static
import com.jakewharton.mosaic.ui.Text

val LocalPrinter = staticCompositionLocalOf { Printer() }

class Printer {
private val messages = SnapshotStateList<String>()
private val messages = SnapshotStateList<AnnotatedString>()

fun printStatic(message: String) {
messages += buildAnnotatedString { append(message) }
}
fun printStatic(message: AnnotatedString) {
messages += message
}

Expand Down

0 comments on commit 9464924

Please sign in to comment.