Last active
February 3, 2026 20:20
-
-
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/436ed487cf9a5fd309bb10110e06cd047db5b35c
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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