mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add color
This commit is contained in:
@@ -113,9 +113,42 @@ public enum Ansi4BitBackgroundColor implements AnsiElement {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ANSI颜色代码
|
||||
*
|
||||
* @param isBackground 是否背景色
|
||||
* @return 颜色代码
|
||||
*/
|
||||
public int getCode(boolean isBackground) {
|
||||
return isBackground ? this.code : this.code - 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取背景色对应的前景色
|
||||
*
|
||||
* @return 前景色
|
||||
*/
|
||||
public Ansi4BitColor asForeground() {
|
||||
return Ansi4BitColor.of(getCode(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StrUtil.toString(this.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code查找对应的Ansi4BitBackgroundColor
|
||||
*
|
||||
* @param code Ansi 4bit 颜色代码
|
||||
* @return Ansi4BitBackgroundColor
|
||||
*/
|
||||
public static Ansi4BitBackgroundColor of(int code) {
|
||||
for (Ansi4BitBackgroundColor item : Ansi4BitBackgroundColor.values()) {
|
||||
if (item.getCode() == code) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(StrUtil.format("No matched Ansi4BitBackgroundColor instance,code={}", code));
|
||||
}
|
||||
}
|
||||
|
@@ -123,9 +123,32 @@ public enum Ansi4BitColor implements AnsiElement {
|
||||
return isBackground ? this.code + 10 : this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取前景色对应的背景色
|
||||
*
|
||||
* @return 背景色
|
||||
*/
|
||||
public Ansi4BitBackgroundColor asBackground() {
|
||||
return Ansi4BitBackgroundColor.of(getCode(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StrUtil.toString(this.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code查找对应的Ansi4BitColor
|
||||
*
|
||||
* @param code Ansi 4bit 颜色代码
|
||||
* @return Ansi4BitColor
|
||||
*/
|
||||
public static Ansi4BitColor of(int code) {
|
||||
for (Ansi4BitColor item : Ansi4BitColor.values()) {
|
||||
if (item.getCode() == code) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(StrUtil.format("No matched Ansi4BitColor instance,code={}", code));
|
||||
}
|
||||
}
|
||||
|
@@ -70,6 +70,30 @@ public class Ansi8BitColor implements AnsiElement {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为前景色
|
||||
*
|
||||
* @return 前景色
|
||||
*/
|
||||
public Ansi8BitColor asForeground() {
|
||||
if (PREFIX_FORE.equals(this.prefix)) {
|
||||
return this;
|
||||
}
|
||||
return Ansi8BitColor.foreground(this.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为背景色
|
||||
*
|
||||
* @return 背景色
|
||||
*/
|
||||
public Ansi8BitColor asBackground() {
|
||||
if (PREFIX_BACK.equals(this.prefix)) {
|
||||
return this;
|
||||
}
|
||||
return Ansi8BitColor.background(this.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@@ -1275,6 +1275,7 @@ public class MapUtil extends MapGetUtil {
|
||||
* @param map Map,一般用于线程安全的Map
|
||||
* @param key 键
|
||||
* @param mappingFunction 值计算函数
|
||||
* @return 值
|
||||
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8161372">https://bugs.openjdk.java.net/browse/JDK-8161372</a>
|
||||
*/
|
||||
public static <K, V> V computeIfAbsent(final Map<K, V> map, final K key, final Function<? super K, ? extends V> mappingFunction) {
|
||||
|
Reference in New Issue
Block a user