< prev index next >

jdk/src/jdk.jline/share/classes/jdk/internal/jline/TerminalFactory.java

Print this page


   1 /*
   2  * Copyright (c) 2002-2012, the original author or authors.
   3  *
   4  * This software is distributable under the BSD license. See the terms of the
   5  * BSD license in the documentation provided with this software.
   6  *
   7  * http://www.opensource.org/licenses/bsd-license.php
   8  */
   9 package jline;
  10 
  11 import java.text.MessageFormat;
  12 import java.util.HashMap;
  13 import java.util.Map;
  14 
  15 import jline.internal.Configuration;
  16 import jline.internal.Log;
  17 import jline.internal.Preconditions;
  18 
  19 import static jline.internal.Preconditions.checkNotNull;
  20 
  21 /**
  22  * Creates terminal instances.
  23  *
  24  * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
  25  * @since 2.0
  26  */
  27 public class TerminalFactory
  28 {
  29     public static final String JLINE_TERMINAL = "jline.terminal";
  30 
  31     public static final String AUTO = "auto";
  32 
  33     public static final String UNIX = "unix";
  34 
  35     public static final String WIN = "win";
  36 
  37     public static final String WINDOWS = "windows";
  38 
  39     public static final String NONE = "none";


 132     }
 133 
 134     public static synchronized void configure(final Type type) {
 135         checkNotNull(type);
 136         configure(type.name().toLowerCase());
 137     }
 138 
 139     //
 140     // Flavor Support
 141     //
 142 
 143     public static enum Flavor
 144     {
 145         WINDOWS,
 146         UNIX
 147     }
 148 
 149     private static final Map<Flavor, Class<? extends Terminal>> FLAVORS = new HashMap<Flavor, Class<? extends Terminal>>();
 150 
 151     static {
 152         registerFlavor(Flavor.WINDOWS, AnsiWindowsTerminal.class);

 153         registerFlavor(Flavor.UNIX, UnixTerminal.class);
 154     }
 155 
 156     public static synchronized Terminal get() {
 157         if (term == null) {
 158             term = create();
 159         }
 160         return term;
 161     }
 162 
 163     public static Terminal getFlavor(final Flavor flavor) throws Exception {
 164         Class<? extends Terminal> type = FLAVORS.get(flavor);
 165         if (type != null) {
 166             return type.newInstance();
 167         }
 168 
 169         throw new InternalError();
 170     }
 171 
 172     public static void registerFlavor(final Flavor flavor, final Class<? extends Terminal> type) {
   1 /*
   2  * Copyright (c) 2002-2012, the original author or authors.
   3  *
   4  * This software is distributable under the BSD license. See the terms of the
   5  * BSD license in the documentation provided with this software.
   6  *
   7  * http://www.opensource.org/licenses/bsd-license.php
   8  */
   9 package jdk.internal.jline;
  10 
  11 import java.text.MessageFormat;
  12 import java.util.HashMap;
  13 import java.util.Map;
  14 
  15 import jdk.internal.jline.internal.Configuration;
  16 import jdk.internal.jline.internal.Log;
  17 import jdk.internal.jline.internal.Preconditions;
  18 import static jdk.internal.jline.internal.Preconditions.checkNotNull;

  19 
  20 /**
  21  * Creates terminal instances.
  22  *
  23  * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
  24  * @since 2.0
  25  */
  26 public class TerminalFactory
  27 {
  28     public static final String JLINE_TERMINAL = "jline.terminal";
  29 
  30     public static final String AUTO = "auto";
  31 
  32     public static final String UNIX = "unix";
  33 
  34     public static final String WIN = "win";
  35 
  36     public static final String WINDOWS = "windows";
  37 
  38     public static final String NONE = "none";


 131     }
 132 
 133     public static synchronized void configure(final Type type) {
 134         checkNotNull(type);
 135         configure(type.name().toLowerCase());
 136     }
 137 
 138     //
 139     // Flavor Support
 140     //
 141 
 142     public static enum Flavor
 143     {
 144         WINDOWS,
 145         UNIX
 146     }
 147 
 148     private static final Map<Flavor, Class<? extends Terminal>> FLAVORS = new HashMap<Flavor, Class<? extends Terminal>>();
 149 
 150     static {
 151 //        registerFlavor(Flavor.WINDOWS, AnsiWindowsTerminal.class);
 152         registerFlavor(Flavor.WINDOWS, WindowsTerminal.class);
 153         registerFlavor(Flavor.UNIX, UnixTerminal.class);
 154     }
 155 
 156     public static synchronized Terminal get() {
 157         if (term == null) {
 158             term = create();
 159         }
 160         return term;
 161     }
 162 
 163     public static Terminal getFlavor(final Flavor flavor) throws Exception {
 164         Class<? extends Terminal> type = FLAVORS.get(flavor);
 165         if (type != null) {
 166             return type.newInstance();
 167         }
 168 
 169         throw new InternalError();
 170     }
 171 
 172     public static void registerFlavor(final Flavor flavor, final Class<? extends Terminal> type) {
< prev index next >