-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,9 +41,27 @@ | |
import java.util.logging.Level; | ||
import org.aesh.terminal.tty.Signal; | ||
import org.aesh.terminal.tty.Size; | ||
import static org.fusesource.jansi.internal.Kernel32.GetStdHandle; | ||
import static org.fusesource.jansi.internal.Kernel32.STD_OUTPUT_HANDLE; | ||
import static org.fusesource.jansi.internal.Kernel32.WriteConsoleW; | ||
import org.fusesource.jansi.internal.WindowsSupport; | ||
|
||
abstract class AbstractWindowsTerminal extends AbstractTerminal { | ||
|
||
private static class ConsoleOutput extends OutputStream { | ||
|
||
private static final long console = GetStdHandle(STD_OUTPUT_HANDLE); | ||
private final int[] writtenChars = new int[1]; | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
char[] chars = new char[]{(char) b}; | ||
if (WriteConsoleW(console, chars, 1, writtenChars, 0) == 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jfdenise
Author
Contributor
|
||
throw new IOException("Failed to write to console: " + WindowsSupport.getLastErrorMessage()); | ||
} | ||
} | ||
|
||
} | ||
private static final int PIPE_SIZE = 1024; | ||
|
||
protected static final int ENABLE_PROCESSED_INPUT = 0x0001; | ||
|
@@ -65,17 +83,21 @@ abstract class AbstractWindowsTerminal extends AbstractTerminal { | |
|
||
private volatile boolean closing; | ||
|
||
public AbstractWindowsTerminal(String name, boolean nativeSignals, SignalHandler signalHandler) throws IOException { | ||
this(null, name, nativeSignals, signalHandler); | ||
} | ||
|
||
public AbstractWindowsTerminal(OutputStream output, String name, boolean nativeSignals, SignalHandler signalHandler) throws IOException { | ||
super(name, "windows", signalHandler); | ||
PipedInputStream input = new PipedInputStream(PIPE_SIZE); | ||
this.slaveInputPipe = new PipedOutputStream(input); | ||
this.input = new FilterInputStream(input) {}; | ||
this.output = output; | ||
this.output = output == null ? new ConsoleOutput() : output; | ||
String encoding = getConsoleEncoding(); | ||
if (encoding == null) { | ||
encoding = Charset.defaultCharset().name(); | ||
} | ||
this.writer = new PrintWriter(new OutputStreamWriter(output, encoding)); | ||
this.writer = new PrintWriter(new OutputStreamWriter(this.output, encoding)); | ||
// Attributes | ||
attributes.setLocalFlag(Attributes.LocalFlag.ISIG, true); | ||
attributes.setControlChar(Attributes.ControlChar.VINTR, ctrl('C')); | ||
|
While the idea of using
WriteConsoleW
is a good one, I think you can't do it here because what you receive is a byte, not a character. Assuming bytes are characters only work for the first 128 chars mostly, everything else will certainly be messed up at display. Try to copyÆsh
in the example running on Windows and it will fail.