src/jdk.internal.le/share/classes/jdk/internal/jline/DefaultTerminal2.java
branchJDK-8200758-branch
changeset 57072 29604aafa0fc
parent 57071 94e9270166f0
parent 52979 7384e00d5860
child 57076 687505381ca4
equal deleted inserted replaced
57071:94e9270166f0 57072:29604aafa0fc
     1 /*
       
     2  * Copyright (c) 2002-2016, 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.io.IOException;
       
    12 import java.io.InputStream;
       
    13 import java.io.OutputStream;
       
    14 import java.util.Collections;
       
    15 import java.util.HashMap;
       
    16 import java.util.HashSet;
       
    17 import java.util.Map;
       
    18 import java.util.Set;
       
    19 
       
    20 import jdk.internal.jline.internal.InfoCmp;
       
    21 
       
    22 /**
       
    23  * Terminal wrapper with default ansi capabilities
       
    24  */
       
    25 public class DefaultTerminal2 implements Terminal2 {
       
    26 
       
    27     private final Terminal terminal;
       
    28     private final Set<String> bools = new HashSet<String>();
       
    29     private final Map<String, String> strings = new HashMap<String, String>();
       
    30 
       
    31     public DefaultTerminal2(Terminal terminal) {
       
    32         this.terminal = terminal;
       
    33         registerCap("key_backspace", "^H");
       
    34         registerCap("bell", "^G");
       
    35         registerCap("carriage_return", "^M");
       
    36         if (true/*isSupported() && isAnsiSupported()*/) {
       
    37             registerCap("clr_eol", "\\E[K");
       
    38             registerCap("clr_bol", "\\E[1K");
       
    39             registerCap("cursor_up", "\\E[A");
       
    40             registerCap("cursor_down", "^J");
       
    41             registerCap("column_address", "\\E[%i%p1%dG");
       
    42             registerCap("clear_screen", "\\E[H\\E[2J");
       
    43             registerCap("parm_down_cursor", "\\E[%p1%dB");
       
    44             registerCap("cursor_left", "^H");
       
    45             registerCap("cursor_right", "\\E[C");
       
    46         }
       
    47         if (hasWeirdWrap()) {
       
    48             registerCap("eat_newline_glitch");
       
    49             registerCap("auto_right_margin");
       
    50         }
       
    51     }
       
    52 
       
    53     public void init() throws Exception {
       
    54         terminal.init();
       
    55     }
       
    56 
       
    57     public void restore() throws Exception {
       
    58         terminal.restore();
       
    59     }
       
    60 
       
    61     public void reset() throws Exception {
       
    62         terminal.reset();
       
    63     }
       
    64 
       
    65     public boolean isSupported() {
       
    66         return terminal.isSupported();
       
    67     }
       
    68 
       
    69     public int getWidth() {
       
    70         return terminal.getWidth();
       
    71     }
       
    72 
       
    73     public int getHeight() {
       
    74         return terminal.getHeight();
       
    75     }
       
    76 
       
    77     public boolean isAnsiSupported() {
       
    78         return terminal.isAnsiSupported();
       
    79     }
       
    80 
       
    81     public OutputStream wrapOutIfNeeded(OutputStream out) {
       
    82         return terminal.wrapOutIfNeeded(out);
       
    83     }
       
    84 
       
    85     public InputStream wrapInIfNeeded(InputStream in) throws IOException {
       
    86         return terminal.wrapInIfNeeded(in);
       
    87     }
       
    88 
       
    89     public boolean hasWeirdWrap() {
       
    90         return terminal.hasWeirdWrap();
       
    91     }
       
    92 
       
    93     public boolean isEchoEnabled() {
       
    94         return terminal.isEchoEnabled();
       
    95     }
       
    96 
       
    97     public void setEchoEnabled(boolean enabled) {
       
    98         terminal.setEchoEnabled(enabled);
       
    99     }
       
   100 
       
   101     public void disableInterruptCharacter() {
       
   102         terminal.disableInterruptCharacter();
       
   103     }
       
   104 
       
   105     public void enableInterruptCharacter() {
       
   106         terminal.enableInterruptCharacter();
       
   107     }
       
   108 
       
   109     public String getOutputEncoding() {
       
   110         return terminal.getOutputEncoding();
       
   111     }
       
   112 
       
   113     private void registerCap(String cap, String value) {
       
   114         for (String key : InfoCmp.getNames(cap)) {
       
   115             strings.put(key, value);
       
   116         }
       
   117     }
       
   118 
       
   119     private void registerCap(String cap) {
       
   120         Collections.addAll(bools, InfoCmp.getNames(cap));
       
   121     }
       
   122 
       
   123     public boolean getBooleanCapability(String capability) {
       
   124         return bools.contains(capability);
       
   125     }
       
   126 
       
   127     public Integer getNumericCapability(String capability) {
       
   128         return null;
       
   129     }
       
   130 
       
   131     public String getStringCapability(String capability) {
       
   132         return strings.get(capability);
       
   133     }
       
   134 
       
   135 }