Skip to content

Commit

Permalink
Update 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed May 3, 2023
1 parent 493f258 commit f16c37b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ android.disableAutomaticComponentCreation=true
# Android targt SDK
andorid.targetSdk=33
# Library version
library.version=1.2.0
library.version=1.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import com.fox2code.androidansi.AnsiParser
import com.fox2code.androidansi.builder.AnnotatedStringAnsiComponentBuilder
import org.jetbrains.annotations.Contract

private fun intAsColor(color: Int): Color {
return Color(android.graphics.Color.red(color),
android.graphics.Color.green(color),
android.graphics.Color.blue(color))
}

@Contract(pure = true)
fun AnsiContext.toAnsiSpanStyle(): SpanStyle {
var baselineShift: BaselineShift = BaselineShift.None
Expand All @@ -23,7 +29,7 @@ fun AnsiContext.toAnsiSpanStyle(): SpanStyle {
} else if (this.style and AnsiConstants.FLAG_STYLE_SUPERSCRIPT != 0) {
baselineShift = BaselineShift.Superscript
}
val backgroundColor: Color = when(val background: ULong =
val backgroundColor: Color = when(
this.background.toULong() or 0xFF000000.toULong()) {
this.defaultBackground.toULong() -> Color.Unspecified
0xFF000000.toULong() -> Color.Black
Expand All @@ -37,9 +43,9 @@ fun AnsiContext.toAnsiSpanStyle(): SpanStyle {
0xFFFFFF00.toULong() -> Color.Yellow
0xFFFFFF00.toULong() -> Color.Cyan
0xFFFFFF00.toULong() -> Color.Magenta
else -> Color(background)
else -> intAsColor(this.background)
}
var foregroundColor: Color = when(val foreground: ULong =
var foregroundColor: Color = when(
this.foreground.toULong() or 0xFF000000.toULong()) {
this.defaultForeground.toULong() -> Color.Unspecified
0xFF000000.toULong() -> Color.Black
Expand All @@ -53,7 +59,7 @@ fun AnsiContext.toAnsiSpanStyle(): SpanStyle {
0xFFFFFF00.toULong() -> Color.Yellow
0xFFFFFF00.toULong() -> Color.Cyan
0xFFFFFF00.toULong() -> Color.Magenta
else -> Color(foreground)
else -> intAsColor(foreground)
}
val textDecoration: TextDecoration = when(this.style and (
AnsiConstants.FLAG_STYLE_UNDERLINE or AnsiConstants.FLAG_STYLE_STRIKE
Expand Down

0 comments on commit f16c37b

Please sign in to comment.