Skip to content

Commit

Permalink
Encoding problems when using JNA Windows terminal implementation #133
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 15, 2017
1 parent 412adbb commit 8b2de8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public Size getSize() {
return size;
}

protected byte[] readConsoleInput() throws IOException {
protected String readConsoleInput() throws IOException {
INPUT_RECORD[] events = WindowsSupport.readConsoleInput(1);
if (events == null) {
return new byte[0];
return "";
}
StringBuilder sb = new StringBuilder();
for (INPUT_RECORD event : events) {
Expand Down Expand Up @@ -112,7 +112,7 @@ protected byte[] readConsoleInput() throws IOException {
}
}
}
return sb.toString().getBytes();
return sb.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public Size getSize() {

private char[] mouse = new char[] { '\033', '[', 'M', ' ', ' ', ' ' };

protected byte[] readConsoleInput() throws IOException {
protected String readConsoleInput() throws IOException {
Kernel32.INPUT_RECORD[] events = doReadConsoleInput();
if (events == null) {
return new byte[0];
return "";
}
StringBuilder sb = new StringBuilder();
for (Kernel32.INPUT_RECORD event : events) {
Expand Down Expand Up @@ -148,7 +148,7 @@ protected byte[] readConsoleInput() throws IOException {
prevButtonState = dwButtonState;
}
}
return sb.toString().getBytes();
return sb.toString();
}

private Kernel32.INPUT_RECORD[] doReadConsoleInput() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public abstract class AbstractWindowsTerminal extends AbstractTerminal {

private static final int PIPE_SIZE = 1024;

private static final Charset INPUT_CHARSET = Charset.forName("UTF-8");

protected static final int ENABLE_PROCESSED_INPUT = 0x0001;
protected static final int ENABLE_LINE_INPUT = 0x0002;
protected static final int ENABLE_ECHO_INPUT = 0x0004;
Expand Down Expand Up @@ -66,7 +68,7 @@ public AbstractWindowsTerminal(OutputStream output, String name, boolean nativeS
if (encoding == null) {
encoding = Charset.defaultCharset().name();
}
this.reader = new NonBlockingReader(getName(), new org.jline.utils.InputStreamReader(input, encoding));
this.reader = new NonBlockingReader(getName(), new org.jline.utils.InputStreamReader(input, INPUT_CHARSET));
this.writer = new PrintWriter(new OutputStreamWriter(output, encoding));
parseInfoCmp();
// Attributes
Expand Down Expand Up @@ -191,7 +193,7 @@ public void close() throws IOException {
writer.close();
}

protected abstract byte[] readConsoleInput() throws IOException;
protected abstract String readConsoleInput() throws IOException;

protected String getEscapeSequence(short keyCode) {
// virtual keycodes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
Expand Down Expand Up @@ -290,8 +292,8 @@ protected String getSequence(InfoCmp.Capability cap) {
protected void pump() {
try {
while (!closing) {
byte[] buf = readConsoleInput();
for (byte b : buf) {
String buf = readConsoleInput();
for (byte b : buf.getBytes(INPUT_CHARSET)) {
processInputByte(b);
}
}
Expand Down

0 comments on commit 8b2de8c

Please sign in to comment.