Created
January 6, 2024 11:36
-
-
Save dacr/cfdc58896515ad1058c2b0874d7159f0 to your computer and use it in GitHub Desktop.
com-lihaoyi fansi basic usage examples / published by https://github.com/dacr/code-examples-manager #a6dcdc25-6a11-4848-a03f-f119e8897b33/95fbbe85fffd7a9a0d1a2077767a852fbbb452cd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : com-lihaoyi fansi basic usage examples | |
// keywords : scala, lihaoyi, fansi, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : a6dcdc25-6a11-4848-a03f-f119e8897b33 | |
// created-on : 2024-01-06T12:16:50+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.3.1" | |
//> using dep "com.lihaoyi::fansi:0.4.0" | |
// --------------------- | |
import fansi.* | |
val helloMessage = "Hello world fansi." | |
val helloMessageRed = Color.Red(helloMessage) | |
val welcomeMessage = "Welcome everybody." | |
val welcomeMessageBlue = Color.Blue(welcomeMessage) | |
val compoundColoredMessage = helloMessageRed ++ welcomeMessageBlue | |
println(helloMessageRed) | |
println(welcomeMessageBlue) | |
println(compoundColoredMessage) | |
assert(helloMessage.size == helloMessageRed.length) | |
val overlayedMessage = | |
compoundColoredMessage.overlay( | |
Attrs(Color.Green, Bold.On, Underlined.On), | |
5, | |
compoundColoredMessage.length - 5 | |
) | |
println(overlayedMessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment