-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Better console color system #134
base: master
Are you sure you want to change the base?
Changes from all commits
893d389
ace7e37
735d12a
ef9bab2
03bd6d6
113302f
27ca17f
cc263cc
578bc75
dad941d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.syst3ms.skriptparser.expressions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this pull request There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was made basing myself on my other PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete the files locally and push the changes here. It will remove the files from the PR as Github compares with the latest commit in the master branch. |
||
|
||
import io.github.syst3ms.skriptparser.Parser; | ||
import io.github.syst3ms.skriptparser.lang.Expression; | ||
import io.github.syst3ms.skriptparser.lang.TriggerContext; | ||
import io.github.syst3ms.skriptparser.lang.base.TaggedExpression; | ||
import io.github.syst3ms.skriptparser.parsing.ParseContext; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* Ask for a specific input in the system console and wait for the answer of the user. | ||
* This will therefore return what the user entered into a string. | ||
* | ||
* @name Ask | ||
* @type EXPRESSION | ||
* @pattern ask [for] %string% | ||
* @since ALPHA | ||
* @author ItsTheSky | ||
*/ | ||
public class ExprAsk implements Expression<String> { | ||
|
||
static { | ||
Parser.getMainRegistration().addExpression( | ||
ExprAsk.class, | ||
String.class, | ||
true, | ||
"ask [for] %string%" | ||
); | ||
} | ||
|
||
private Expression<String> message; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContext context) { | ||
message = (Expression<String>) expressions[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String[] getValues(TriggerContext ctx) { | ||
Scanner scanner = new Scanner(System.in); | ||
for (String line : TaggedExpression.apply(message, ctx, "console")) | ||
System.out.println(line); | ||
return new String[]{scanner.nextLine()}; | ||
} | ||
|
||
@Override | ||
public String toString(TriggerContext ctx, boolean debug) { | ||
return "ask for " + message.toString(ctx, debug); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.syst3ms.skriptparser.tags; | ||
|
||
import io.github.syst3ms.skriptparser.Parser; | ||
import io.github.syst3ms.skriptparser.registration.tags.ContinuousTag; | ||
import io.github.syst3ms.skriptparser.util.color.ConsoleColors; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
public class TagColor implements ContinuousTag { | ||
|
||
static { | ||
Parser.getMainRegistration().addTag(TagColor.class); | ||
} | ||
|
||
private ConsoleColors color; | ||
|
||
@Override | ||
public boolean init(String key, String[] parameters) { | ||
final Optional<ConsoleColors> optional; | ||
if (key.equalsIgnoreCase("color") && parameters.length != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should check for length 1. |
||
optional = ConsoleColors.search(parameters[0]); | ||
} else { | ||
optional = ConsoleColors.search(key); | ||
} | ||
|
||
if (optional.isEmpty()) | ||
return false; | ||
|
||
color = optional.get(); | ||
return color != ConsoleColors.RESET; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return color.toString(); | ||
} | ||
|
||
@Override | ||
public String toString(boolean debug) { | ||
return "<color="+color.name().toLowerCase()+">"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import io.github.syst3ms.skriptparser.Parser; | ||
import io.github.syst3ms.skriptparser.registration.tags.Tag; | ||
import io.github.syst3ms.skriptparser.util.color.ConsoleColors; | ||
|
||
/** | ||
* A tag that resets all currently ongoing tags. | ||
|
@@ -24,7 +25,7 @@ public boolean init(String key, String[] parameters) { | |
} | ||
|
||
public String getValue(String affected) { | ||
return affected; | ||
return ConsoleColors.RESET + affected; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this implementation is correct for now, it reminds me that a small overhaul of the tag system is needed in order to give addons the flexibility of changing the reset tag. |
||
} | ||
|
||
public String toString(boolean debug) { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.github.syst3ms.skriptparser.util.color; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
public enum ConsoleColors { | ||
|
||
// Reset | ||
RESET("0", true), | ||
|
||
// Normal Colors | ||
BLACK("30", false), | ||
RED("31", false), | ||
GREEN("32", false, "dark_green"), | ||
ORANGE("33", false, "orange", "amber"), | ||
BLUE("34", false, "dark_blue"), | ||
PURPLE("35", false, "dark_pink"), | ||
CYAN("36", false, "dark_aqua"), | ||
WHITE("37", false, "dark_gray"), | ||
|
||
// Bright Colors | ||
BLACK_BRIGHT("90", false, "gray", "grey"), | ||
RED_BRIGHT("91", false, "pink"), | ||
GREEN_BRIGHT("92", false, "lime", "light_green"), | ||
ORANGE_BRIGHT("93", false, "yellow"), | ||
BLUE_BRIGHT("94", false, "light_blue"), | ||
PURPLE_BRIGHT("95", false, "light_purple"), | ||
CYAN_BRIGHT("96", false, "light_aqua", "aqua"), | ||
WHITE_BRIGHT("97", false), | ||
|
||
// Colors background | ||
BLACK_BACKGROUND(BLACK, "40"), | ||
RED_BACKGROUND(RED, "41"), | ||
GREEN_BACKGROUND(GREEN, "42"), | ||
ORANGE_BACKGROUND(ORANGE, "43"), | ||
BLUE_BACKGROUND(BLUE, "44"), | ||
PURPLE_BACKGROUND(PURPLE, "45"), | ||
CYAN_BACKGROUND(CYAN, "46"), | ||
WHITE_BACKGROUND(WHITE, "47"), | ||
|
||
// Styles | ||
BOLD("1", true, "b"), | ||
ITALIC("3", true, "o", "it", "i"), | ||
UNDERLINE("4", true, "n", "u"), | ||
STRIKETHROUGH("9", true, "m", "strike", "s"), | ||
; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something wrong here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks line 46 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't see what's wrong, is it the constant's name ? |
||
|
||
private static final String ANSI_DELIMITER = "\033["; | ||
|
||
private final String code; | ||
private final boolean style; | ||
private final String[] aliases; | ||
|
||
/** | ||
* Used for backgrounds colors only. | ||
* It will generate values according to it. | ||
* @param color | ||
*/ | ||
ConsoleColors(ConsoleColors color, String code) { | ||
this.code = code; | ||
this.style = false; | ||
this.aliases = Stream.of(color.getAliases()) | ||
.map(alias -> alias + "_background") | ||
.toArray(String[]::new); | ||
} | ||
|
||
ConsoleColors(String code, boolean style, String... aliases) { | ||
this.code = code; | ||
this.style = style; | ||
this.aliases = aliases; | ||
} | ||
|
||
public static Optional<ConsoleColors> search(String input) { | ||
for (ConsoleColors color : values()) { | ||
if (color.match(input)) | ||
return Optional.of(color); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public String format() { | ||
return ANSI_DELIMITER + code + "m"; | ||
} | ||
|
||
public boolean match(String other) { | ||
if (other.replace(" ", "_").equalsIgnoreCase(name())) | ||
return true; | ||
// Checking for aliases | ||
for (String alias : aliases) { | ||
if (other.replace(" ", "_").equalsIgnoreCase(alias)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public String toString() { | ||
return format(); | ||
} | ||
|
||
public String[] getAliases() { | ||
return aliases; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public boolean isStyle() { | ||
return style; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think change to orange is a good idea since yellow is in general associate with warning so it would imo create bad idea of warning for skript users that would next switch to another language