From 9464924c6711a7424bf84c76f4e006ba0f61e859 Mon Sep 17 00:00:00 2001 From: Matthew Precious Date: Fri, 27 Dec 2024 18:18:46 -0500 Subject: [PATCH] Support annotated strings for static logging --- .../com/mattprecious/stacker/command/StackerCommand.kt | 5 +++++ .../kotlin/com/mattprecious/stacker/rendering/printer.kt | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/mattprecious/stacker/command/StackerCommand.kt b/src/commonMain/kotlin/com/mattprecious/stacker/command/StackerCommand.kt index 1d70a3a..9e8d28b 100644 --- a/src/commonMain/kotlin/com/mattprecious/stacker/command/StackerCommand.kt +++ b/src/commonMain/kotlin/com/mattprecious/stacker/command/StackerCommand.kt @@ -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 @@ -91,6 +92,10 @@ internal abstract class StackerCommand( printer.printStatic(message) } + fun printStatic(message: AnnotatedString) { + printer.printStatic(message) + } + suspend fun render(content: @Composable (onResult: (R) -> Unit) -> Unit): R { state.value = State.Rendering(content) return state.filterIsInstance>().first().result.also { diff --git a/src/commonMain/kotlin/com/mattprecious/stacker/rendering/printer.kt b/src/commonMain/kotlin/com/mattprecious/stacker/rendering/printer.kt index 3c9726e..1ac9e00 100644 --- a/src/commonMain/kotlin/com/mattprecious/stacker/rendering/printer.kt +++ b/src/commonMain/kotlin/com/mattprecious/stacker/rendering/printer.kt @@ -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() + private val messages = SnapshotStateList() fun printStatic(message: String) { + messages += buildAnnotatedString { append(message) } + } + fun printStatic(message: AnnotatedString) { messages += message }