diff --git a/src/main/java/jline/WindowsTerminal.java b/src/main/java/jline/WindowsTerminal.java index 6f30afb..7cb067a 100644 --- a/src/main/java/jline/WindowsTerminal.java +++ b/src/main/java/jline/WindowsTerminal.java @@ -190,10 +190,11 @@ public class WindowsTerminal extends Terminal { private boolean echoEnabled; String encoding = System.getProperty("jline.WindowsTerminal.input.encoding", System.getProperty("file.encoding")); - ReplayPrefixOneCharInputStream replayStream = new ReplayPrefixOneCharInputStream(encoding); + ReplayPrefixOneCharInputStream replayStream; InputStreamReader replayReader; public WindowsTerminal() { + replayStream = new ReplayPrefixOneCharInputStream(this, encoding); String dir = System.getProperty("jline.WindowsTerminal.directConsole"); if ("true".equals(dir)) { @@ -357,7 +358,6 @@ public class WindowsTerminal extends Terminal { replayStream.setInput(indicator, in); // replayReader = new InputStreamReader(replayStream, encoding); indicator = replayReader.read(); - } return indicator; @@ -453,8 +453,10 @@ public class WindowsTerminal extends Terminal { int byteRead; final String encoding; + final WindowsTerminal terminal; - public ReplayPrefixOneCharInputStream(String encoding) { + public ReplayPrefixOneCharInputStream(WindowsTerminal terminal, String encoding) { + this.terminal = terminal; this.encoding = encoding; } @@ -470,9 +472,21 @@ public class WindowsTerminal extends Terminal { byteLength = 2; else if (encoding.equalsIgnoreCase("UTF-32")) byteLength = 4; + else if (encoding.equalsIgnoreCase("MS932") + || encoding.equalsIgnoreCase("Windows-31J") + || encoding.equalsIgnoreCase("Shift_JIS")) + setInputMS932(recorded, wrapped); } + public void setInputMS932(int recorded, InputStream wrapped) throws IOException { + int n = firstByte & 0xff; + if (0x81 <= n && n <= 0x9f || 0xe0 <= n && n <= 0xfc) { + this.byteLength = 2; + } else { + this.byteLength = 1; + } + } public void setInputUTF8(int recorded, InputStream wrapped) throws IOException { // 110yyyyy 10zzzzzz if ((firstByte & (byte) 0xE0) == (byte) 0xC0) @@ -496,7 +510,7 @@ public class WindowsTerminal extends Terminal { if (byteRead == 1) return firstByte; - return wrappedStream.read(); + return terminal.readCharacter(wrappedStream); } /** @@ -509,5 +523,4 @@ public class WindowsTerminal extends Terminal { return byteLength - byteRead; } } - }