Created
January 16, 2023 17:11
-
-
Save roschlau/07b7db113e1eae27c15f23d6a1de4773 to your computer and use it in GitHub Desktop.
Utility code to style console output
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
fun styled(style: AnsiStyle, str: String) = style.code + str + AnsiStyle.RESET | |
interface AnsiStyle { | |
val code: String | |
companion object { | |
const val RESET = "\u001B[0m" | |
} | |
} | |
@Suppress("unused") | |
enum class Color(override val code: String) : AnsiStyle { | |
BLACK("\u001B[30m"), | |
RED("\u001B[31m"), | |
GREEN("\u001B[32m"), | |
YELLOW("\u001B[33m"), | |
BLUE("\u001B[34m"), | |
PURPLE("\u001B[35m"), | |
CYAN("\u001B[36m"), | |
WHITE("\u001B[37m"), | |
BLACK_BRIGHT("\u001b[0;90m"), | |
RED_BRIGHT("\u001b[0;91m"), | |
GREEN_BRIGHT("\u001b[0;92m"), | |
YELLOW_BRIGHT("\u001b[0;93m"), | |
BLUE_BRIGHT("\u001b[0;94m"), | |
PURPLE_BRIGHT("\u001b[0;95m"), | |
CYAN_BRIGHT("\u001b[0;96m"), | |
WHITE_BRIGHT("\u001b[0;97m"), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment