diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bcd60f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) +!/.mvn/wrapper/maven-wrapper.jar +/plugin + +# IntelliJ IDEA +.idea/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c44733c --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +### PackMake +Resource pack compiler + +##### Usage, commands and flags +... to be added diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b695248 --- /dev/null +++ b/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + + com.github.ijustleyxo + packmake + 0.0.0 + + PackMake + https://github.com/iJustLeyxo/PackMake + jar + + + UTF-8 + + + + ${project.name} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + true + true + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.2 + + + + true + com.github.ijustleyxo.packmake.PackMake + + + + + + + + + + org.jetbrains + annotations + 24.0.0 + compile + + + org.jetbrains + annotations + 24.1.0 + compile + + + diff --git a/src/main/java/com/github/ijustleyxo/packmake/PackMake.java b/src/main/java/com/github/ijustleyxo/packmake/PackMake.java new file mode 100644 index 0000000..54cf75a --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/PackMake.java @@ -0,0 +1,20 @@ +package com.github.ijustleyxo.packmake; + +import com.github.ijustleyxo.packmake.util.console.Console; +import com.github.ijustleyxo.packmake.util.console.Type; + +/** + * Minecraft resource pack compiler + */ +public final class PackMake { + public static void main(String[] args) { + // TODO: Resource pack creation logic + PackMake.exit(); + } + + public static void exit() { + Console.log(Type.DEBUG, "Exiting\n"); + Console.sep(); + System.exit(0); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/ijustleyxo/packmake/util/console/Console.java b/src/main/java/com/github/ijustleyxo/packmake/util/console/Console.java new file mode 100644 index 0000000..c1fb947 --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/util/console/Console.java @@ -0,0 +1,156 @@ +package com.github.ijustleyxo.packmake.util.console; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; + +/** + * Console manager, used to format console outputs + */ +public final class Console { + public static @NotNull Detail detail = Detail.STD; + private static @Nullable Type type = null; + private static boolean empty = true; + + /** + * Logs a message to console + * @param type Type of message to log + * @param style Style to override the default style of the specified type + * @param msg Message to log + * @return {@code true} if the message was logged and not held back due to verbosity + */ + public static boolean log(@NotNull Type type, @NotNull Style style, @NotNull String msg) { + if (!Console.logs(type.detail)) return false; + Console.sep(type); + System.out.print(XCode.RESET + style.toString() + msg); + Console.empty = false; + return true; + } + + /** + * Logs a formatted message to console + * @param type Type of message to log + * @param style Style to override the default style of the specified type + * @param format Format to use for the message + * @param params Params to format + * @return {@code true} if the message was logged and not held back due to verbosity + */ + public static boolean logF(@NotNull Type type, @NotNull Style style, @NotNull String format, @NotNull String... params) { + if (!Console.logs(type.detail)) return false; + Console.sep(type); + System.out.printf(XCode.RESET + style.toString() + format, (Object[]) params); + Console.empty = false; + return true; + } + + /** + * Logs a list to console + * @param type Type of message to log + * @param style Style to override the default style of the specified type + * @param header List header + * @param cols Columns of the list + * @param colSize Size of the columns of the list + * @return {@code true} if the message was logged and not held back due to verbosity + */ + public static boolean logL(@NotNull Type type, @NotNull Style style, @NotNull String header, + int cols, int colSize, @NotNull Object... objects) { + if (!Console.logs(type.detail)) return false; + int dashes = (cols * colSize + cols - 1) - header.length() - 2; + StringBuilder b = new StringBuilder(XCode.BOLD + "-".repeat(dashes / 2) + " " + header + " " + + "-".repeat(dashes / 2 + dashes % 2) + "\n" + XCode.WEIGHT_OFF); + Arrays.sort(objects); + int i = 1; + for (Object o : objects) { + b.append(o).append(" ".repeat(Math.max(0, colSize - o.toString().length()))); + if (i >= cols) { + b.append("\n"); + i = 1; + } else { + b.append(" "); + i++; + } + } + String s = b.toString(); + if (!s.endsWith("\n")) s += "\n"; + Console.log(type, style, s); + return true; + } + + /** + * Logs a style to console + * @param type Type of style to log + * @param style Style to override the default style of the specified type + * @return {@code true} if the style was logged and not held back due to verbosity + */ + public static boolean log(@NotNull Type type, @NotNull Style style) { + return Console.log(type, style, ""); + } + + /** + * Logs a message to console + * @param type Type of message to log using the default style of the type + * @return {@code true} if the style was logged and not held back due to verbosity + */ + public static boolean log(@NotNull Type type, @NotNull String msg) { + return Console.log(type, type.style, msg); + } + + /** + * @param detail The detail to test for logging + * @return {@code true} if the detail level gets logged and not held back due to verbosity + */ + public static boolean logs(@NotNull Detail detail) { + return Console.detail.val >= detail.val; + } + + public static boolean logs(@NotNull Type type) { + return Console.logs(type.detail); + } + + /** + * Test for separation between different types of logged output + * @param type The type to test for separation, {@code type = null} will always separate + */ + public static void sep(@Nullable Type type) { + if (Console.type != type || null == type) { + if (!Console.empty) System.out.println(); + Console.type = type; + Console.empty = true; + } + } + + /** + * Force separation between logged outputs + */ + public static void sep() { + Console.sep(null); + } + + /** + * Get new input arguments from console + * @return user input argument + */ + public static @NotNull String @NotNull [] in() { + Console.sep(); + Console.log(Type.PROMPT, "> "); + Console.log(Type.PROMPT, Style.INPUT); + return System.console().readLine().split(" "); + } + + /** + * Get an input from console + * @param prompt Prompt to output + * @return user's response to the prompt + */ + public static @NotNull String in(@NotNull String prompt) { + Console.sep(); + Console.log(Type.PROMPT, prompt + " "); + Console.log(Type.PROMPT, Style.INPUT); + return System.console().readLine(); + } + + public static boolean confirm(@NotNull String string) { + return Console.in(string + " (Y/n)?").equalsIgnoreCase("y"); + } +} diff --git a/src/main/java/com/github/ijustleyxo/packmake/util/console/Detail.java b/src/main/java/com/github/ijustleyxo/packmake/util/console/Detail.java new file mode 100644 index 0000000..4b215a1 --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/util/console/Detail.java @@ -0,0 +1,21 @@ +package com.github.ijustleyxo.packmake.util.console; + +/** + * Console output detail level + */ +public enum Detail { + /** + * Override detail management and force console output + */ + OVERRIDE(Integer.MIN_VALUE), + MIN(-2), + LOW(-1), + STD(0), + HIGH(1); + + public final int val; + + Detail(int val) { + this.val = val; + } +} diff --git a/src/main/java/com/github/ijustleyxo/packmake/util/console/Style.java b/src/main/java/com/github/ijustleyxo/packmake/util/console/Style.java new file mode 100644 index 0000000..8afb050 --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/util/console/Style.java @@ -0,0 +1,42 @@ +package com.github.ijustleyxo.packmake.util.console; + +import org.jetbrains.annotations.NotNull; + +/** + * Console output styles, used to manage color, weight, etc. of console outputs + */ +public enum Style { + PROMPT(XCode.BOLD, XCode.BLUE), + INPUT(XCode.BOLD, XCode.WHITE), + DEBUG(XCode.GRAY), + SELECT(XCode.BLUE), + INSTALL(XCode.GREEN), + UPDATE(XCode.GREEN), + UNINSTALL(XCode.RED), + LINK(XCode.MAGENTA), + SUPERFLUOUS(XCode.YELLOW), + MISSING(XCode.RED), + UNKNOWN(XCode.GRAY), + PLUGIN(XCode.BLUE), + CATEGORY(XCode.GREEN), + SERVER(XCode.MAGENTA), + SOFTWARE(XCode.YELLOW), + INFO(XCode.WHITE), + DONE(XCode.GREEN), + HELP(XCode.GREEN), + WARN(XCode.BOLD, XCode.YELLOW), + ERR(XCode.BOLD, XCode.RED); + + public final @NotNull String xCodes; + + Style(@NotNull XCode @NotNull ... codes) { + StringBuilder s = new StringBuilder(); + for (XCode c : codes) { + s.append(c); + } + this.xCodes = s.toString(); + } + + @Override + public @NotNull String toString() { return this.xCodes; } +} diff --git a/src/main/java/com/github/ijustleyxo/packmake/util/console/Type.java b/src/main/java/com/github/ijustleyxo/packmake/util/console/Type.java new file mode 100644 index 0000000..9f77c82 --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/util/console/Type.java @@ -0,0 +1,23 @@ +package com.github.ijustleyxo.packmake.util.console; + +import org.jetbrains.annotations.NotNull; + +/** + * Console output type, used to combine commonly used combinations of a style and detail level + */ +public enum Type { + PROMPT(Detail.OVERRIDE, Style.PROMPT), + REQUESTED(Detail.OVERRIDE, Style.INFO), + DEBUG(Detail.HIGH, Style.DEBUG), + INFO(Detail.STD, Style.INFO), + WARN(Detail.LOW, Style.WARN), + ERR(Detail.MIN, Style.ERR); + + public final @NotNull Detail detail; + public final @NotNull Style style; + + Type(@NotNull Detail detail, @NotNull Style style) { + this.detail = detail; + this.style = style; + } +} diff --git a/src/main/java/com/github/ijustleyxo/packmake/util/console/XCode.java b/src/main/java/com/github/ijustleyxo/packmake/util/console/XCode.java new file mode 100644 index 0000000..1b93a81 --- /dev/null +++ b/src/main/java/com/github/ijustleyxo/packmake/util/console/XCode.java @@ -0,0 +1,30 @@ +package com.github.ijustleyxo.packmake.util.console; + +import org.jetbrains.annotations.NotNull; + +/** + * ANSI escape codes, used to format text outputted to most modern terminal emulators + */ +public enum XCode { + RESET("\u001B[0m"), + BOLD("\u001B[1m"), + WEIGHT_OFF("\u001B[22m"), + GRAY("\u001B[90m"), + RED("\u001B[91m"), + GREEN("\u001B[92m"), + YELLOW("\u001B[93m"), + BLUE("\u001B[94m"), + MAGENTA("\u001B[95m"), + WHITE("\u001B[97m"); + + private final @NotNull String code; + + XCode(@NotNull String code) { + this.code = code; + } + + @Override + public @NotNull String toString() { + return this.code; + } +}