1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 15:58:52 -05:00

Support for more escape codes

This commit is contained in:
Reinhard Pointner 2018-06-23 15:56:14 +07:00
parent c877f3cc05
commit d34594c53e
2 changed files with 20 additions and 13 deletions

View File

@ -138,13 +138,10 @@ public final class Logging {
@Override
public String format(LogRecord record) {
StringWriter buffer = new StringWriter();
EscapeCode color = getColor(record.getLevel().intValue());
// BEGIN COLOR
EscapeCode color = getColor(record.getLevel().intValue());
if (color != null) {
buffer.append(color.begin);
}
StringWriter buffer = new StringWriter().append(color.begin);
// MESSAGE
String message = record.getMessage();
@ -166,11 +163,7 @@ public final class Logging {
}
// END COLOR
if (color != null) {
buffer.append(color.end);
}
return buffer.append(System.lineSeparator()).toString();
return buffer.append(color.end).append(System.lineSeparator()).toString();
}
public EscapeCode getColor(int level) {
@ -187,7 +180,7 @@ public final class Logging {
return EscapeCode.CHERRY_RED; // SEVERE
}
return null; // NO COLOR
return EscapeCode.NONE; // NO COLOR
}
}
@ -232,6 +225,8 @@ public final class Logging {
public static final EscapeCode UNDERLINE = newFontStyle(4);
public static final EscapeCode STRIKEOUT = newFontStyle(9);
public static final EscapeCode NONE = new EscapeCode("", "");
public static EscapeCode newColorStyle(int color) {
return new EscapeCode("38;5;" + color);
}

View File

@ -19,10 +19,11 @@ import javax.script.SimpleBindings;
import org.apache.commons.io.IOUtils;
import net.filebot.LicenseError;
import net.filebot.Logging.EscapeCode;
public class ArgumentProcessor {
public int run(ArgumentBean args) throws Exception {
public int run(ArgumentBean args) {
try {
// interactive mode enables basic selection and confirmation dialogs in the CLI
CmdlineInterface cli = args.isInteractive() ? new CmdlineOperationsTextUI() : new CmdlineOperations();
@ -41,7 +42,7 @@ public class ArgumentProcessor {
} catch (LicenseError e) {
log.severe("License Error: " + e.getMessage());
if (LICENSE.isFile()) {
log.info(format(IOUtils.toString(getClass().getResource("Stegosaurus.format"), UTF_8), getPurchaseURL()));
printStegosaurus();
log.severe("FileBot requires a valid license. Please run `filebot --license *.psm` to install your FileBot license.");
}
return 2;
@ -130,6 +131,17 @@ public class ArgumentProcessor {
}).sum() == 0 ? 1 : 0;
}
private void printStegosaurus() {
try {
String format = IOUtils.toString(getClass().getResource("Stegosaurus.format"), UTF_8);
EscapeCode style = EscapeCode.isSupported() ? EscapeCode.UNDERLINE : EscapeCode.NONE;
String url = getPurchaseURL();
log.info(format(format, style.apply(url)));
} catch (Exception e) {
debug.log(Level.WARNING, e::toString);
}
}
public void runScript(CmdlineInterface cli, ArgumentBean args) throws Throwable {
Bindings bindings = new SimpleBindings();
bindings.put(ScriptShell.SHELL_ARGS_BINDING_NAME, args);