mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Fix console when using dumb terminal
This commit is contained in:
@@ -6,6 +6,7 @@ import org.jline.reader.EndOfFileException;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.UserInterruptException;
|
||||
import org.jline.reader.impl.LineReaderImpl;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -24,7 +25,6 @@ import lombok.Getter;
|
||||
|
||||
public class LunarCore {
|
||||
private static final Logger log = (Logger) LoggerFactory.getLogger(LunarCore.class);
|
||||
private static LineReaderImpl reader;
|
||||
private static File configFile = new File("./config.json");
|
||||
private static Config config;
|
||||
|
||||
@@ -36,6 +36,9 @@ public class LunarCore {
|
||||
|
||||
@Getter private static CommandManager commandManager;
|
||||
@Getter private static ServerType serverType = ServerType.BOTH;
|
||||
|
||||
private static LineReaderImpl reader;
|
||||
@Getter private static boolean usingDumbTerminal;
|
||||
|
||||
static {
|
||||
// Setup console reader
|
||||
@@ -43,6 +46,8 @@ public class LunarCore {
|
||||
reader = (LineReaderImpl) LineReaderBuilder.builder()
|
||||
.terminal(TerminalBuilder.builder().dumb(true).build())
|
||||
.build();
|
||||
|
||||
usingDumbTerminal = Terminal.TYPE_DUMB.equals(reader.getTerminal().getType());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -12,20 +12,22 @@ import emu.lunarcore.util.Utils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kcp.highway.Ukcp;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class GameSession {
|
||||
@Getter private final GameServer server;
|
||||
@Getter private InetSocketAddress address;
|
||||
private final GameServer server;
|
||||
private InetSocketAddress address;
|
||||
|
||||
@Getter private Account account;
|
||||
@Getter private Player player;
|
||||
private Account account;
|
||||
private Player player;
|
||||
|
||||
// Network
|
||||
private Ukcp ukcp;
|
||||
@Getter(AccessLevel.PRIVATE) private Ukcp ukcp;
|
||||
|
||||
// Flags
|
||||
@Getter private SessionState state = SessionState.WAITING_FOR_TOKEN;
|
||||
private SessionState state = SessionState.WAITING_FOR_TOKEN;
|
||||
private boolean useSecretKey;
|
||||
|
||||
private GameSession(GameServer server) {
|
||||
@@ -168,8 +170,7 @@ public class GameSession {
|
||||
}
|
||||
|
||||
public void logPacket(String sendOrRecv, int opcode, byte[] payload) {
|
||||
LunarCore.getLogger().info(sendOrRecv + ": " + CmdIdUtils.getOpcodeName(opcode) + " (" + opcode + ")");
|
||||
LunarCore.getLineReader().printAbove(Utils.bytesToHex(payload));
|
||||
LunarCore.getLogger().info(sendOrRecv + ": " + CmdIdUtils.getOpcodeName(opcode) + " (" + opcode + ")" + System.lineSeparator() + Utils.bytesToHex(payload));
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package emu.lunarcore.util;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.PatternLayout;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
@@ -26,6 +26,10 @@ public class LunarConsoleAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent event) {
|
||||
LunarCore.getLineReader().printAbove(layout.doLayout(event));
|
||||
if (LunarCore.isUsingDumbTerminal()) {
|
||||
System.out.print(layout.doLayout(event));
|
||||
} else {
|
||||
LunarCore.getLineReader().printAbove(layout.doLayout(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user