-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
21 changed files
with
712 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/thecrownstudios/minestomlauncher/console/ConsoleAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.thecrownstudios.minestomlauncher.console; | ||
|
||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy; | ||
import org.apache.logging.log4j.core.config.Property; | ||
import org.apache.logging.log4j.core.layout.PatternLayout; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jline.reader.LineReader; | ||
|
||
final class ConsoleAppender extends AbstractAppender { | ||
private final LineReader lineReader; | ||
private final @Nullable RewritePolicy rewriter; | ||
|
||
ConsoleAppender( | ||
final LineReader lineReader, | ||
final String logPattern, | ||
final @Nullable RewritePolicy rewritePolicy | ||
) { | ||
super( | ||
"Console", | ||
null, | ||
PatternLayout.newBuilder().withPattern(logPattern).build(), | ||
false, | ||
new Property[0] | ||
); | ||
this.lineReader = lineReader; | ||
this.rewriter = rewritePolicy; | ||
} | ||
|
||
private LogEvent rewrite(final LogEvent event) { | ||
return this.rewriter == null ? event : this.rewriter.rewrite(event); | ||
} | ||
|
||
@Override | ||
public void append(final LogEvent event) { | ||
if (this.lineReader.isReading()) { | ||
this.lineReader.callWidget(LineReader.CLEAR); | ||
} | ||
|
||
this.lineReader.getTerminal().writer().print(this.getLayout().toSerializable(this.rewrite(event)).toString()); | ||
|
||
if (this.lineReader.isReading()) { | ||
this.lineReader.callWidget(LineReader.REDRAW_LINE); | ||
this.lineReader.callWidget(LineReader.REDISPLAY); | ||
} | ||
this.lineReader.getTerminal().writer().flush(); | ||
} | ||
} |
Oops, something went wrong.