1 19 package jline; 20 21 import java.io.*; 22 import java.util.*; 23 24 25 33 public abstract class Terminal 34 { 35 private static Terminal term; 36 37 38 41 public static Terminal getTerminal () 42 { 43 return setupTerminal (); 44 } 45 46 47 62 public static synchronized Terminal setupTerminal () 63 { 64 if (term != null) 65 return term; 66 67 final Terminal t; 68 69 String os = System.getProperty ("os.name").toLowerCase (); 70 String termProp = System.getProperty ("jline.terminal"); 71 if (termProp != null && termProp.length () > 0) 72 { 73 try 74 { 75 t = (Terminal)Class.forName (termProp).newInstance (); 76 } 77 catch (Exception e) 78 { 79 throw (IllegalArgumentException )new IllegalArgumentException ( 80 e.toString ()).fillInStackTrace (); 81 } 82 } 83 else if (os.indexOf ("windows") != -1) 84 { 85 t = new WindowsTerminal (); 86 } 87 else 88 { 89 t = new UnixTerminal (); 90 } 91 92 try 93 { 94 t.initializeTerminal (); 95 } 96 catch (Exception e) 97 { 98 e.printStackTrace (); 99 return term = new UnsupportedTerminal (); 100 } 101 102 return term = t; 103 } 104 105 106 112 public abstract void initializeTerminal () 113 throws Exception ; 114 115 116 119 public abstract int getTerminalWidth (); 120 121 122 125 public abstract int getTerminalHeight (); 126 127 128 132 public abstract boolean isSupported (); 133 134 135 138 public abstract boolean getEcho (); 139 } 140 | Popular Tags |