From da1fed63bd3f9bb75bff755ee252b54228d2bebf Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 13 Apr 2019 06:06:20 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=92=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF=D1=80=D1=8F=D0=BC?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0=D0=BC=D0=B8?= =?UTF-8?q?=20JAnsi=20=D1=81=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=D1=8E?= =?UTF-8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9=20LogHelper.raw*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/utils/helper/LogHelper.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java index edaf7188..a5667c48 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java @@ -17,6 +17,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; public final class LogHelper { @LauncherAPI @@ -183,6 +184,30 @@ public static void log(Level level, String message, boolean sub) { } } } + @LauncherAPI + public static void rawLog(Supplier plainStr, Supplier 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 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) { + + 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; boolean bright = level != Level.DEBUG; switch (level) { @@ -333,10 +367,9 @@ private static String ansiFormatLog(Level level, String dateTime, String message if (sub) { ansi.a(' ').a(Ansi.Attribute.ITALIC); } - ansi.a(message); // Finish with reset code - return ansi.reset().toString(); + return ansi; } 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) { - if (sub) { - message = ' ' + message; - } - return dateTime + " [" + level.name + "] " + message; + return rawFormat(level, dateTime, sub) + message; + } + + public static String rawFormat(Level level, String dateTime, boolean sub) + { + return dateTime + " [" + level.name + (sub ? "] " : "] "); } private static String formatVersion(String product) {