Skip to content

Instantly share code, notes, and snippets.

@roschlau
Created January 16, 2023 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roschlau/07b7db113e1eae27c15f23d6a1de4773 to your computer and use it in GitHub Desktop.
Save roschlau/07b7db113e1eae27c15f23d6a1de4773 to your computer and use it in GitHub Desktop.
Utility code to style console output
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