From 31d488a3861e60f44703958e36d6eabe422f5f41 Mon Sep 17 00:00:00 2001 From: EdGruberman Date: Wed, 14 Mar 2012 13:59:14 -0700 Subject: [PATCH] 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. --- pom.xml | 2 +- .../net/minecraft/server/MinecraftServer.java | 11 +++- .../minecraft/server/ThreadCommandReader.java | 2 +- .../org/bukkit/craftbukkit/CraftServer.java | 2 +- .../command/ColouredConsoleSender.java | 51 +++++++++++-------- .../util/TerminalConsoleHandler.java | 10 ++-- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index af8c5d9a57..cbe4679223 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ jline jline - 0.9.94 + 2.6 jar compile diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index d569ef568a..d6f69c998e 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -16,7 +16,7 @@ import java.util.logging.Logger; import java.io.PrintStream; import java.io.PrintWriter; import java.net.UnknownHostException; -import jline.ConsoleReader; +import jline.console.ConsoleReader; import joptsimple.OptionSet; import org.bukkit.World.Environment; import org.bukkit.command.ConsoleCommandSender; @@ -91,7 +91,8 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe // CraftBukkit start this.options = options; try { - this.reader = new ConsoleReader(System.in, new PrintWriter(System.out)); // CraftBukkit - Added "System.in, new PrintWriter(System.out)" in the constuctor + this.reader = new ConsoleReader(System.in, System.out); + this.reader.setExpandEvents(false); // Avoid parsing exceptions for uncommonly used event designators } catch (IOException ex) { Logger.getLogger(MinecraftServer.class.getName()).log(Level.SEVERE, null, ex); } @@ -478,6 +479,12 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe try { this.stop(); this.isStopped = true; + // CraftBukkit start - restore terminal to original settings + try { + this.reader.getTerminal().restore(); + } catch (Exception e) { + } + // CraftBukkit end } catch (Throwable throwable1) { throwable1.printStackTrace(); } finally { diff --git a/src/main/java/net/minecraft/server/ThreadCommandReader.java b/src/main/java/net/minecraft/server/ThreadCommandReader.java index 09505ff600..e48aa73378 100644 --- a/src/main/java/net/minecraft/server/ThreadCommandReader.java +++ b/src/main/java/net/minecraft/server/ThreadCommandReader.java @@ -21,7 +21,7 @@ public class ThreadCommandReader extends Thread { } // CraftBukkit end - jline.ConsoleReader bufferedreader = this.server.reader; // CraftBukkit + jline.console.ConsoleReader bufferedreader = this.server.reader; // CraftBukkit String s = null; try { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 04d825d6ad..00a82f2fbc 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -120,7 +120,7 @@ import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation; import com.google.common.collect.ImmutableList; import com.google.common.collect.MapMaker; -import jline.ConsoleReader; +import jline.console.ConsoleReader; public final class CraftServer implements Server { private final String serverName = "CraftBukkit"; diff --git a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java index c5c817c8ec..a54b2faeb8 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java +++ b/src/main/java/org/bukkit/craftbukkit/command/ColouredConsoleSender.java @@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.command; import java.util.EnumMap; import java.util.Map; -import jline.ANSIBuffer.ANSICodes; -import jline.ConsoleReader; +import org.fusesource.jansi.Ansi; +import org.fusesource.jansi.Ansi.Attribute; +import jline.console.ConsoleReader; import jline.Terminal; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -21,37 +22,43 @@ public class ColouredConsoleSender extends CraftConsoleCommandSender { this.reader = ((CraftServer) getServer()).getReader(); this.terminal = reader.getTerminal(); - replacements.put(ChatColor.BLACK, ANSICodes.attrib(0)); - replacements.put(ChatColor.DARK_BLUE, ANSICodes.attrib(34)); - replacements.put(ChatColor.DARK_GREEN, ANSICodes.attrib(32)); - replacements.put(ChatColor.DARK_AQUA, ANSICodes.attrib(36)); - replacements.put(ChatColor.DARK_RED, ANSICodes.attrib(31)); - replacements.put(ChatColor.DARK_PURPLE, ANSICodes.attrib(35)); - replacements.put(ChatColor.GOLD, ANSICodes.attrib(33)); - replacements.put(ChatColor.GRAY, ANSICodes.attrib(37)); - replacements.put(ChatColor.DARK_GRAY, ANSICodes.attrib(0)); - replacements.put(ChatColor.BLUE, ANSICodes.attrib(34)); - replacements.put(ChatColor.GREEN, ANSICodes.attrib(32)); - replacements.put(ChatColor.AQUA, ANSICodes.attrib(36)); - replacements.put(ChatColor.RED, ANSICodes.attrib(31)); - replacements.put(ChatColor.LIGHT_PURPLE, ANSICodes.attrib(35)); - replacements.put(ChatColor.YELLOW, ANSICodes.attrib(33)); - replacements.put(ChatColor.WHITE, ANSICodes.attrib(37)); + replacements.put(ChatColor.BLACK, Ansi.ansi().fg(Ansi.Color.BLACK).toString()); + replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().fg(Ansi.Color.BLUE).toString()); + replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().fg(Ansi.Color.GREEN).toString()); + replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().fg(Ansi.Color.CYAN).toString()); + replacements.put(ChatColor.DARK_RED, Ansi.ansi().fg(Ansi.Color.RED).toString()); + replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().fg(Ansi.Color.MAGENTA).toString()); + replacements.put(ChatColor.GOLD, Ansi.ansi().fg(Ansi.Color.YELLOW).bold().toString()); + replacements.put(ChatColor.GRAY, Ansi.ansi().fg(Ansi.Color.WHITE).toString()); + replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().fg(Ansi.Color.BLACK).bold().toString()); + replacements.put(ChatColor.BLUE, Ansi.ansi().fg(Ansi.Color.BLUE).bold().toString()); + replacements.put(ChatColor.GREEN, Ansi.ansi().fg(Ansi.Color.GREEN).bold().toString()); + replacements.put(ChatColor.AQUA, Ansi.ansi().fg(Ansi.Color.CYAN).bold().toString()); + replacements.put(ChatColor.RED, Ansi.ansi().fg(Ansi.Color.RED).bold().toString()); + replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().fg(Ansi.Color.MAGENTA).bold().toString()); + replacements.put(ChatColor.YELLOW, Ansi.ansi().fg(Ansi.Color.YELLOW).bold().toString()); + 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 public void sendMessage(String message) { - if (terminal.isANSISupported()) { + if (terminal.isAnsiSupported()) { if (!conversationTracker.isConversingModaly()) { String result = message; for (ChatColor color : colors) { if (replacements.containsKey(color)) { - result = result.replaceAll(color.toString(), replacements.get(color)); + result = result.replaceAll("(?i)" + color.toString(), replacements.get(color)); } 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 { super.sendMessage(message); diff --git a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleHandler.java b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleHandler.java index 111123f5cf..57dab074f1 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleHandler.java +++ b/src/main/java/org/bukkit/craftbukkit/util/TerminalConsoleHandler.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; -import jline.ConsoleReader; +import jline.console.ConsoleReader; import org.bukkit.craftbukkit.Main; public class TerminalConsoleHandler extends ConsoleHandler { @@ -19,15 +19,15 @@ public class TerminalConsoleHandler extends ConsoleHandler { public synchronized void flush() { try { if (Main.useJline) { - reader.printString(ConsoleReader.RESET_LINE + ""); - reader.flushConsole(); + reader.print(ConsoleReader.RESET_LINE + ""); + reader.flush(); super.flush(); try { reader.drawLine(); } catch (Throwable ex) { - reader.getCursorBuffer().clearBuffer(); + reader.getCursorBuffer().clear(); } - reader.flushConsole(); + reader.flush(); } else { super.flush(); }