Skip to content

Instantly share code, notes, and snippets.

object ColorMeter {
def hexToRGB(hex: String): (Int,Int,Int) = {
def toInt(str: String)(s: Int, e: Int) =
Integer.parseInt(str.substring(s,e), 16)
val hex_1 = if (hex(0)=='#') hex.substring(1,7) else hex
val r = toInt(hex_1)(0,2)
val g = toInt(hex_1)(2,4)
val b = toInt(hex_1)(4,6)
@dainkaplan
dainkaplan / Ansi.java
Last active February 2, 2024 15:12
Simple ANSI colors class for terminal code for JVM written in Scala and Java (two implementations)
package org.tempura.console.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Usage:
* <li>String msg = Ansi.Red.and(Ansi.BgYellow).format("Hello %s", name)</li>
* <li>String msg = Ansi.Blink.colorize("BOOM!")</li>