mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
错误修正,更新AnsiEncoderTest
This commit is contained in:
parent
e78273af7f
commit
a90664b3d7
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.lang.ansi;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -39,9 +40,19 @@ public class AnsiColorWrapper {
|
||||
public AnsiElement toAnsiElement(ForeOrBack foreOrBack){
|
||||
if (bitDepth== AnsiColors.BitDepth.FOUR){
|
||||
if (foreOrBack == ForeOrBack.FORE){
|
||||
return AnsiColor.valueOf(String.valueOf(code));
|
||||
for (AnsiColor item : AnsiColor.values()) {
|
||||
if (StrUtil.equals(item.toString(), StrUtil.toString(code))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(StrUtil.format("No matched AnsiColor instance,code={}",code));
|
||||
}
|
||||
return AnsiBackground.valueOf(String.valueOf(code + 10));
|
||||
for (AnsiBackground item : AnsiBackground.values()) {
|
||||
if (StrUtil.equals(item.toString(), StrUtil.toString(code+10))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(StrUtil.format("No matched Background instance,code=",code));
|
||||
}
|
||||
if (foreOrBack == ForeOrBack.FORE){
|
||||
return Ansi8BitColor.foreground(code);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.lang.ansi;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@ -37,4 +38,31 @@ public class AnsiEncoderTest {
|
||||
//Console.print( i%2==1?encode+"\n":encode);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void colorMappingTest(){
|
||||
String text4 = "RGB:({},{},{})--4bit ";
|
||||
String text8 = "RGB:({},{},{})--8bit ";
|
||||
final AnsiColors ansiColors4Bit = new AnsiColors(AnsiColors.BitDepth.FOUR);
|
||||
final AnsiColors ansiColors8Bit = new AnsiColors(AnsiColors.BitDepth.EIGHT);
|
||||
int count = 0;
|
||||
int from = 100000;
|
||||
int until = 120000;
|
||||
for (int r = 0; r < 256; r++) {
|
||||
if (count>until)break;
|
||||
for (int g = 0; g < 256; g++) {
|
||||
if (count>until)break;
|
||||
for (int b = 0; b < 256; b++) {
|
||||
count++;
|
||||
if (count<from)continue;
|
||||
if (count>until)break;
|
||||
AnsiElement backElement4bit = ansiColors4Bit.findClosest(new Color(r,g,b)).toAnsiElement(AnsiColorWrapper.ForeOrBack.BACK);
|
||||
AnsiElement backElement8bit = ansiColors8Bit.findClosest(new Color(r,g,b)).toAnsiElement(AnsiColorWrapper.ForeOrBack.BACK);
|
||||
String encode4 = AnsiEncoder.encode( backElement4bit,text4);
|
||||
String encode8 = AnsiEncoder.encode( backElement8bit,text8);
|
||||
//Console.log(StrUtil.format(encode4,r,g,b)+StrUtil.format(encode8,r,g,b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user