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.
This commit is contained in:
EdGruberman 2012-03-14 13:59:14 -07:00 committed by Travis Watkins
parent cbd20ec9ea
commit 31d488a386
6 changed files with 46 additions and 32 deletions

View File

@ -72,7 +72,7 @@
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.94</version>
<version>2.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -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 {

View File

@ -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 {

View File

@ -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";

View File

@ -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);

View File

@ -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();
}