[FEATURE] Возможность прямого управления цветами JAnsi с помощью функций LogHelper.raw*

This commit is contained in:
Gravit 2019-04-13 06:06:20 +07:00
parent 5612776da0
commit da1fed63bd
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -17,6 +17,7 @@
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
public final class LogHelper { public final class LogHelper {
@LauncherAPI @LauncherAPI
@ -183,6 +184,30 @@ public static void log(Level level, String message, boolean sub) {
} }
} }
} }
@LauncherAPI
public static void rawLog(Supplier<String> plainStr, Supplier<String> jansiStr)
{
String jansiString = null, plainString = null;
for (OutputEnity output : OUTPUTS) {
if (output.type == OutputTypes.JANSI && JANSI) {
if (jansiString != null) {
output.output.println(jansiString);
continue;
}
jansiString = jansiStr.get();
output.output.println(jansiString);
} else {
if (plainString != null) {
output.output.println(plainString);
continue;
}
plainString = plainStr.get();
output.output.println(plainString);
}
}
}
@LauncherAPI @LauncherAPI
public static void printVersion(String product) { public static void printVersion(String product) {
@ -297,6 +322,15 @@ public static void warning(String format, Object... args) {
} }
private static String ansiFormatLog(Level level, String dateTime, String message, boolean sub) { private static String ansiFormatLog(Level level, String dateTime, String message, boolean sub) {
Ansi ansi = rawAnsiFormat(level, dateTime, sub);
ansi.a(message);
// Finish with reset code
return ansi.reset().toString();
}
public static Ansi rawAnsiFormat(Level level, String dateTime, boolean sub)
{
Color levelColor; Color levelColor;
boolean bright = level != Level.DEBUG; boolean bright = level != Level.DEBUG;
switch (level) { switch (level) {
@ -333,10 +367,9 @@ private static String ansiFormatLog(Level level, String dateTime, String message
if (sub) { if (sub) {
ansi.a(' ').a(Ansi.Attribute.ITALIC); ansi.a(' ').a(Ansi.Attribute.ITALIC);
} }
ansi.a(message);
// Finish with reset code // Finish with reset code
return ansi.reset().toString(); return ansi;
} }
private static String ansiFormatVersion(String product) { private static String ansiFormatVersion(String product) {
@ -359,10 +392,12 @@ private static String ansiFormatLicense(String product) {
} }
private static String formatLog(Level level, String message, String dateTime, boolean sub) { private static String formatLog(Level level, String message, String dateTime, boolean sub) {
if (sub) { return rawFormat(level, dateTime, sub) + message;
message = ' ' + message; }
}
return dateTime + " [" + level.name + "] " + message; public static String rawFormat(Level level, String dateTime, boolean sub)
{
return dateTime + " [" + level.name + (sub ? "] " : "] ");
} }
private static String formatVersion(String product) { private static String formatVersion(String product) {