scoop:scoop.terminal:0.1.0
src/style/content_style.scoop
Selected production source · src/style/content_style.scoop
1
package scoop.terminal.style3
/**4
* An immutable combination of optional foreground/background/underline colors and SGR attributes.5
*/6
public struct ContentStyle(7
val foregroundColor: Color? = None,8
val backgroundColor: Color? = None,9
val underlineColor: Color? = None,10
val attributes: Attributes = Attributes()11
) {12
/**13
* Returns a copy with the selected optional foreground color.14
*/15
public fun withForegroundColor(color: Color?): ContentStyle =16
ContentStyle(color, backgroundColor, underlineColor, attributes)17
/**18
* Returns a copy with the selected optional background color.19
*/20
public fun withBackgroundColor(color: Color?): ContentStyle =21
ContentStyle(foregroundColor, color, underlineColor, attributes)22
/**23
* Returns a copy with the selected optional underline color.24
*/25
public fun withUnderlineColor(color: Color?): ContentStyle =26
ContentStyle(foregroundColor, backgroundColor, color, attributes)27
/**28
* Returns a copy with the selected attribute included.29
*/30
public fun withAttribute(attribute: Attribute): ContentStyle =31
ContentStyle(foregroundColor, backgroundColor, underlineColor, attributes.with(attribute))32
/**33
* Returns a copy without the selected attribute.34
*/35
public fun withoutAttribute(attribute: Attribute): ContentStyle =36
ContentStyle(foregroundColor, backgroundColor, underlineColor, attributes.without(attribute))37
/**38
* Pairs this style with content without writing to a terminal.39
*/40
public fun <T : ToString> apply(content: T): StyledContent<T> = StyledContent(this, content)41
}43
/**44
* Pairs the receiver with a style for later ANSI serialization.45
*/46
public fun <T : ToString> T.styled(style: ContentStyle = ContentStyle()): StyledContent<T> = style.apply(this)