From dd86654b51f3100566d92ba9155ca4fb204989f0 Mon Sep 17 00:00:00 2001 From: Matthew Precious Date: Fri, 27 Dec 2024 23:37:52 -0500 Subject: [PATCH] Add annotated string styles --- .../mattprecious/stacker/rendering/styles.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/commonMain/kotlin/com/mattprecious/stacker/rendering/styles.kt b/src/commonMain/kotlin/com/mattprecious/stacker/rendering/styles.kt index 4556007..62e45e8 100644 --- a/src/commonMain/kotlin/com/mattprecious/stacker/rendering/styles.kt +++ b/src/commonMain/kotlin/com/mattprecious/stacker/rendering/styles.kt @@ -2,16 +2,29 @@ package com.mattprecious.stacker.rendering import com.github.ajalt.colormath.model.RGB import com.github.ajalt.mordant.rendering.TextStyle +import com.jakewharton.mosaic.text.AnnotatedString +import com.jakewharton.mosaic.text.SpanStyle +import com.jakewharton.mosaic.ui.Color +import com.jakewharton.mosaic.ui.TextStyle.Companion.Italic private val branch = TextStyle( color = RGB("#bd93f9"), italic = true, ) +private val branchStyle = SpanStyle( + color = Color(189, 147, 249), + textStyle = Italic, +) + private val code = TextStyle( color = RGB("#61afef"), ) +private val codeStyle = SpanStyle( + color = Color(97, 175, 239), +) + fun String.styleBranch(): String { return branch(this) } @@ -19,3 +32,20 @@ fun String.styleBranch(): String { fun String.styleCode(): String { return code(this) } + +fun AnnotatedString.Builder.branch(content: AnnotatedString.Builder.() -> Unit) { + withStyle(branchStyle, content) +} + +fun AnnotatedString.Builder.code(content: AnnotatedString.Builder.() -> Unit) { + withStyle(codeStyle, content) +} + +private fun AnnotatedString.Builder.withStyle( + style: SpanStyle, + content: AnnotatedString.Builder.() -> Unit, +) { + pushStyle(style) + content() + pop() +}