Skip to content

Commit

Permalink
Pass the console handle directly to the WindowsAnsiProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 3, 2020
1 parent cc7c8d9 commit 2babe3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ else if (IS_CONEMU || IS_CYGWIN || IS_MSYSTEM) {
AnsiProcessor proc;
AnsiProcessorType type;
try {
proc = new WindowsAnsiProcessor(out, stdout);
proc = new WindowsAnsiProcessor(out, console);
type = AnsiProcessorType.Emulation;
} catch (Throwable ignore) {
// this happens when the stdout is being redirected to a file.
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/fusesource/jansi/WindowsAnsiProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
*/
public final class WindowsAnsiProcessor extends AnsiProcessor {

private static final long stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
private static final long stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
private final long console;

private static final short FOREGROUND_BLACK = 0;
Expand Down Expand Up @@ -100,13 +98,17 @@ public final class WindowsAnsiProcessor extends AnsiProcessor {
private short savedX = -1;
private short savedY = -1;

public WindowsAnsiProcessor(OutputStream ps, boolean stdout) throws IOException {
public WindowsAnsiProcessor(OutputStream ps, long console) throws IOException {
super(ps);
this.console = stdout ? stdout_handle : stderr_handle;
this.console = console;
getConsoleInfo();
originalColors = info.attributes;
}

public WindowsAnsiProcessor(OutputStream ps, boolean stdout) throws IOException {
this(ps, GetStdHandle(stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE));
}

public WindowsAnsiProcessor(OutputStream ps) throws IOException {
this(ps, true);
}
Expand Down

0 comments on commit 2babe3d

Please sign in to comment.