Personal tools
You are here: Home ブログ sugawara Stuff jline-ime.patch
« December 2010 »
Su Mo Tu We Th Fr Sa
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Recent entries
jlineで日本語を使えるようにする。 sugawara 2009-12-10
五反田Emacsの資料 sugawara 2009-10-19
trac-ticket.el sugawara 2007-11-19
Emacs Lisp 勉強会(バッファとウィンドウ編) sugawara 2007-10-22
Categories
Emacs
勉強会
java
 
Document Actions

jline-ime.patch

Click here to get the file

Size 2.9 kB - File type text/x-patch

File contents

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;
         }
     }
-    
 }

Copyright(C) 2001 - 2006 Ariel Networks, Inc. All rights reserved.