Skip to content

Commit

Permalink
Add annotated string styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattprecious committed Dec 28, 2024
1 parent 9464924 commit dd86654
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/commonMain/kotlin/com/mattprecious/stacker/rendering/styles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@ 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)
}

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()
}

0 comments on commit dd86654

Please sign in to comment.