mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 11:24:11 +01:00
Update to jline 2. Fixes BUKKIT-717
JLine 2 allows for better color matching in the console and support for colors in console on Windows. Hopefully provides better performance as well. By: EdGruberman <ed@rjump.com>
This commit is contained in:
parent
e8795d1897
commit
01b14886d7
4 changed files with 36 additions and 29 deletions
|
@ -72,7 +72,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jline</groupId>
|
<groupId>jline</groupId>
|
||||||
<artifactId>jline</artifactId>
|
<artifactId>jline</artifactId>
|
||||||
<version>0.9.94</version>
|
<version>2.6</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -120,7 +120,7 @@ import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
|
|
||||||
import jline.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
|
|
||||||
public final class CraftServer implements Server {
|
public final class CraftServer implements Server {
|
||||||
private final String serverName = "CraftBukkit";
|
private final String serverName = "CraftBukkit";
|
||||||
|
|
|
@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.command;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jline.ANSIBuffer.ANSICodes;
|
import org.fusesource.jansi.Ansi;
|
||||||
import jline.ConsoleReader;
|
import org.fusesource.jansi.Ansi.Attribute;
|
||||||
|
import jline.console.ConsoleReader;
|
||||||
import jline.Terminal;
|
import jline.Terminal;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
@ -21,37 +22,43 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender {
|
||||||
this.reader = ((CraftServer) getServer()).getReader();
|
this.reader = ((CraftServer) getServer()).getReader();
|
||||||
this.terminal = reader.getTerminal();
|
this.terminal = reader.getTerminal();
|
||||||
|
|
||||||
replacements.put(ChatColor.BLACK, ANSICodes.attrib(0));
|
replacements.put(ChatColor.BLACK, Ansi.ansi().fg(Ansi.Color.BLACK).toString());
|
||||||
replacements.put(ChatColor.DARK_BLUE, ANSICodes.attrib(34));
|
replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().fg(Ansi.Color.BLUE).toString());
|
||||||
replacements.put(ChatColor.DARK_GREEN, ANSICodes.attrib(32));
|
replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().fg(Ansi.Color.GREEN).toString());
|
||||||
replacements.put(ChatColor.DARK_AQUA, ANSICodes.attrib(36));
|
replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().fg(Ansi.Color.CYAN).toString());
|
||||||
replacements.put(ChatColor.DARK_RED, ANSICodes.attrib(31));
|
replacements.put(ChatColor.DARK_RED, Ansi.ansi().fg(Ansi.Color.RED).toString());
|
||||||
replacements.put(ChatColor.DARK_PURPLE, ANSICodes.attrib(35));
|
replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().fg(Ansi.Color.MAGENTA).toString());
|
||||||
replacements.put(ChatColor.GOLD, ANSICodes.attrib(33));
|
replacements.put(ChatColor.GOLD, Ansi.ansi().fg(Ansi.Color.YELLOW).bold().toString());
|
||||||
replacements.put(ChatColor.GRAY, ANSICodes.attrib(37));
|
replacements.put(ChatColor.GRAY, Ansi.ansi().fg(Ansi.Color.WHITE).toString());
|
||||||
replacements.put(ChatColor.DARK_GRAY, ANSICodes.attrib(0));
|
replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().fg(Ansi.Color.BLACK).bold().toString());
|
||||||
replacements.put(ChatColor.BLUE, ANSICodes.attrib(34));
|
replacements.put(ChatColor.BLUE, Ansi.ansi().fg(Ansi.Color.BLUE).bold().toString());
|
||||||
replacements.put(ChatColor.GREEN, ANSICodes.attrib(32));
|
replacements.put(ChatColor.GREEN, Ansi.ansi().fg(Ansi.Color.GREEN).bold().toString());
|
||||||
replacements.put(ChatColor.AQUA, ANSICodes.attrib(36));
|
replacements.put(ChatColor.AQUA, Ansi.ansi().fg(Ansi.Color.CYAN).bold().toString());
|
||||||
replacements.put(ChatColor.RED, ANSICodes.attrib(31));
|
replacements.put(ChatColor.RED, Ansi.ansi().fg(Ansi.Color.RED).bold().toString());
|
||||||
replacements.put(ChatColor.LIGHT_PURPLE, ANSICodes.attrib(35));
|
replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().fg(Ansi.Color.MAGENTA).bold().toString());
|
||||||
replacements.put(ChatColor.YELLOW, ANSICodes.attrib(33));
|
replacements.put(ChatColor.YELLOW, Ansi.ansi().fg(Ansi.Color.YELLOW).bold().toString());
|
||||||
replacements.put(ChatColor.WHITE, ANSICodes.attrib(37));
|
replacements.put(ChatColor.WHITE, Ansi.ansi().fg(Ansi.Color.WHITE).bold().toString());
|
||||||
|
replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Attribute.BLINK_SLOW).toString());
|
||||||
|
replacements.put(ChatColor.BOLD, Ansi.ansi().a(Attribute.UNDERLINE_DOUBLE).toString());
|
||||||
|
replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Attribute.STRIKETHROUGH_ON).toString());
|
||||||
|
replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Attribute.UNDERLINE).toString());
|
||||||
|
replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Attribute.ITALIC).toString());
|
||||||
|
replacements.put(ChatColor.RESET, Ansi.ansi().a(Attribute.RESET).fg(Ansi.Color.DEFAULT).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
if (terminal.isANSISupported()) {
|
if (terminal.isAnsiSupported()) {
|
||||||
if (!conversationTracker.isConversingModaly()) {
|
if (!conversationTracker.isConversingModaly()) {
|
||||||
String result = message;
|
String result = message;
|
||||||
for (ChatColor color : colors) {
|
for (ChatColor color : colors) {
|
||||||
if (replacements.containsKey(color)) {
|
if (replacements.containsKey(color)) {
|
||||||
result = result.replaceAll(color.toString(), replacements.get(color));
|
result = result.replaceAll("(?i)" + color.toString(), replacements.get(color));
|
||||||
} else {
|
} else {
|
||||||
result = result.replaceAll(color.toString(), "");
|
result = result.replaceAll("(?i)" + color.toString(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(result + ANSICodes.attrib(0));
|
System.out.println(result + Ansi.ansi().reset().toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.sendMessage(message);
|
super.sendMessage(message);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
||||||
import java.util.logging.ConsoleHandler;
|
import java.util.logging.ConsoleHandler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import jline.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import org.bukkit.craftbukkit.Main;
|
import org.bukkit.craftbukkit.Main;
|
||||||
|
|
||||||
public class TerminalConsoleHandler extends ConsoleHandler {
|
public class TerminalConsoleHandler extends ConsoleHandler {
|
||||||
|
@ -19,15 +19,15 @@ public class TerminalConsoleHandler extends ConsoleHandler {
|
||||||
public synchronized void flush() {
|
public synchronized void flush() {
|
||||||
try {
|
try {
|
||||||
if (Main.useJline) {
|
if (Main.useJline) {
|
||||||
reader.printString(ConsoleReader.RESET_LINE + "");
|
reader.print(ConsoleReader.RESET_LINE + "");
|
||||||
reader.flushConsole();
|
reader.flush();
|
||||||
super.flush();
|
super.flush();
|
||||||
try {
|
try {
|
||||||
reader.drawLine();
|
reader.drawLine();
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
reader.getCursorBuffer().clearBuffer();
|
reader.getCursorBuffer().clear();
|
||||||
}
|
}
|
||||||
reader.flushConsole();
|
reader.flush();
|
||||||
} else {
|
} else {
|
||||||
super.flush();
|
super.flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue