Last active
May 25, 2024 10:19
-
-
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/dbd8fb79622917a0fcaea427f64641cb0040df4c
This file contains hidden or 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.4.2" | |
//> 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