1 19 package jline; 20 21 import java.io.*; 22 import java.util.*; 23 24 28 43 public class WindowsTerminal 44 extends Terminal 45 { 46 48 54 private static final int ENABLE_LINE_INPUT = 2; 55 56 57 63 private static final int ENABLE_ECHO_INPUT = 4; 64 65 66 75 private static final int ENABLE_PROCESSED_INPUT = 1; 76 77 78 85 private static final int ENABLE_WINDOW_INPUT = 8; 86 87 88 95 private static final int ENABLE_MOUSE_INPUT = 16; 96 97 98 106 private static final int ENABLE_PROCESSED_OUTPUT = 1; 107 108 109 114 private static final int ENABLE_WRAP_AT_EOL_OUTPUT = 2; 115 116 117 118 private native int getConsoleMode (); 119 120 private native void setConsoleMode (int mode); 121 122 123 public void initializeTerminal () 124 throws Exception 125 { 126 loadLibrary ("jline"); 127 128 final int originalMode = getConsoleMode (); 129 130 setConsoleMode (originalMode & ~ENABLE_ECHO_INPUT); 131 132 int newMode = originalMode 134 & ~(ENABLE_LINE_INPUT 135 | ENABLE_ECHO_INPUT 136 | ENABLE_PROCESSED_INPUT 137 | ENABLE_WINDOW_INPUT); 138 setConsoleMode (newMode); 139 140 try 142 { 143 Runtime.getRuntime ().addShutdownHook (new Thread () 144 { 145 public void start () 146 { 147 setConsoleMode (originalMode); 149 } 150 }); 151 } 152 catch (AbstractMethodError ame) 153 { 154 } 156 } 157 158 159 private void loadLibrary (String name) 160 throws IOException 161 { 162 String version = getClass ().getPackage ().getImplementationVersion (); 164 if (version == null) 165 version = ""; 166 version = version.replace ('.', '_'); 167 168 File f = new File (System.getProperty ("java.io.tmpdir"), 169 name + "_" + version + ".dll"); 170 boolean exists = f.isFile (); 172 InputStream in = new BufferedInputStream (getClass () 175 .getResourceAsStream (name + ".dll")); 176 177 try 178 { 179 OutputStream fout = new BufferedOutputStream ( 180 new FileOutputStream (f)); 181 byte[] bytes = new byte [1024 * 10]; 182 for (int n = 0; n != -1; n = in.read (bytes)) 183 fout.write (bytes, 0, n); 184 185 fout.close (); 186 } 187 catch (IOException ioe) 188 { 189 if (!exists) 193 throw ioe; 194 } 195 196 f.deleteOnExit (); 198 199 System.load (f.getAbsolutePath ()); 201 } 202 203 204 public boolean isSupported () 205 { 206 return true; 207 } 208 209 210 public boolean getEcho () 211 { 212 return false; 213 } 214 215 216 221 public int getTerminalWidth () 222 { 223 return 80; 224 } 225 226 227 232 public int getTerminalHeight () 233 { 234 return 24; 235 } 236 } 237 238 | Popular Tags |