Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 20, 2024
1 parent 2b5a2b5 commit b31600b
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
package eu.maveniverse.maven.toolbox.cli;

import static org.jline.jansi.Ansi.Attribute.INTENSITY_BOLD;
import static org.jline.jansi.Ansi.Attribute.INTENSITY_BOLD_OFF;
import static org.jline.jansi.Ansi.Attribute.INTENSITY_FAINT;
import static org.jline.jansi.Ansi.Attribute.ITALIC;
import static org.jline.jansi.Ansi.Attribute.ITALIC_OFF;
import static org.jline.jansi.Ansi.Color.RED;
import static org.jline.jansi.Ansi.Color.WHITE;
import static org.jline.jansi.Ansi.Color.YELLOW;
Expand Down Expand Up @@ -276,13 +279,14 @@ protected void verbose(String format, Object... args) {
if (!verbose) {
return;
}
if (args[args.length - 1] instanceof Throwable) {
if (args.length > 0 && args[args.length - 1] instanceof Throwable) {
log(
System.err,
ansi().a(INTENSITY_FAINT)
.fg(WHITE)
.a(MessageFormatter.arrayFormat(format, Arrays.copyOfRange(args, 0, args.length - 1))
.getMessage())
.reset()
.toString(),
(Throwable) args[args.length - 1]);
} else {
Expand All @@ -297,55 +301,54 @@ protected void verbose(String format, Object... args) {
}

protected void normal(String format, Object... args) {
if (args[args.length - 1] instanceof Throwable) {
if (args.length > 0 && args[args.length - 1] instanceof Throwable) {
log(
System.err,
ansi().a(INTENSITY_BOLD)
.fg(WHITE)
ansi().fg(WHITE)
.a(MessageFormatter.arrayFormat(format, Arrays.copyOfRange(args, 0, args.length - 1))
.getMessage())
.reset()
.toString(),
(Throwable) args[args.length - 1]);
} else {
log(
System.err,
ansi().a(INTENSITY_BOLD)
.fg(WHITE)
ansi().fg(WHITE)
.a(MessageFormatter.arrayFormat(format, args).getMessage())
.reset()
.toString());
}
}

protected void warn(String format, Object... args) {
if (args[args.length - 1] instanceof Throwable) {
if (args.length > 0 && args[args.length - 1] instanceof Throwable) {
log(
System.err,
ansi().a(INTENSITY_BOLD)
.fg(YELLOW)
ansi().fg(YELLOW)
.a(MessageFormatter.arrayFormat(format, Arrays.copyOfRange(args, 0, args.length - 1))
.getMessage())
.reset()
.toString(),
(Throwable) args[args.length - 1]);
} else {
log(
System.err,
ansi().a(INTENSITY_BOLD)
.fg(YELLOW)
ansi().fg(YELLOW)
.a(MessageFormatter.arrayFormat(format, args).getMessage())
.reset()
.toString());
}
}

protected void error(String format, Object... args) {
if (args[args.length - 1] instanceof Throwable) {
if (args.length > 0 && args[args.length - 1] instanceof Throwable) {
log(
System.err,
ansi().a(INTENSITY_BOLD)
.fg(RED)
.a(MessageFormatter.arrayFormat(format, Arrays.copyOfRange(args, 0, args.length - 1))
.getMessage())
.reset()
.toString(),
(Throwable) args[args.length - 1]);
} else {
Expand All @@ -366,15 +369,14 @@ private void log(PrintStream ps, String message) {
private void log(PrintStream ps, String message, Throwable throwable) {
ps.println(message);
writeThrowable(throwable, ps);
ps.println(ansi().reset());
}

private static String failure(String format) {
return ansi().a(INTENSITY_BOLD).a(format).reset().toString();
return ansi().a(ITALIC).a(format).a(ITALIC_OFF).toString();
}

private static String strong(String format) {
return ansi().a(INTENSITY_BOLD).a(format).reset().toString();
return ansi().a(INTENSITY_BOLD).a(format).a(INTENSITY_BOLD_OFF).toString();
}

private void writeThrowable(Throwable t, PrintStream stream) {
Expand All @@ -390,6 +392,7 @@ private void writeThrowable(Throwable t, PrintStream stream) {
if (errors) {
printStackTrace(t, stream, "");
}
stream.println(ansi().reset());
}

private void printStackTrace(Throwable t, PrintStream stream, String prefix) {
Expand Down

0 comments on commit b31600b

Please sign in to comment.