org.aesh.terminal.tty.Capability Java Examples

The following examples show how to use org.aesh.terminal.tty.Capability. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfoCmpTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testNative() throws IOException, InterruptedException {
    if(Config.isOSPOSIXCompatible()) {
        Set<Capability> bools = new HashSet<>();
        Map<Capability, Integer> ints = new HashMap<>();
        Map<Capability, String> strings = new HashMap<>();

        String infocmp = InfoCmp.getInfoCmp("xterm-256color");
        if(infocmp != null) {
            InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);

            assertEquals(256, ints.get(Capability.max_colors).intValue());
            assertTrue(ints.get(Capability.columns) > 0);
            assertTrue(ints.get(Capability.lines) > 0);
            assertTrue(bools.size() > 0);
            assertTrue(strings.size() > 0);
        }
    }
}
 
Example #2
Source File: InfoCmpTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testWindows() {
    Set<Capability> bools = new HashSet<>();
    Map<Capability, Integer> ints = new HashMap<>();
    Map<Capability, String> strings = new HashMap<>();

    String infocmp = InfoCmp.getDefaultInfoCmp("Windows");
    InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
    assertEquals(24, ints.get(Capability.lines).intValue());
    assertEquals(64, ints.get(Capability.max_pairs).intValue());

    assertEquals(6, ints.size());
    assertEquals(4, bools.size());
    assertEquals(58, strings.size());
    assertTrue(strings.containsKey(Capability.byName("smso")));
}
 
Example #3
Source File: InfoCmpTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testANSI() {
    Set<Capability> bools = new HashSet<>();
    Map<Capability, Integer> ints = new HashMap<>();
    Map<Capability, String> strings = new HashMap<>();

    String infocmp = InfoCmp.getDefaultInfoCmp("xterm");
    InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
    assertEquals(24, ints.get(Capability.lines).intValue());
    assertEquals(80, ints.get(Capability.columns).intValue());

    assertEquals(5, ints.size());
    assertEquals(8, bools.size());
    assertEquals(166, strings.size());
    assertTrue(strings.containsKey(Capability.byName("kf29")));
}
 
Example #4
Source File: InfoCmpHelper.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public static String getCurrentTranslatedCapability(String cap, String defaultValue) {
    try {
        if (!initialized) {
            String term = System.getenv("TERM");
            if (term == null) {
                term = "xterm-256color";
            }
            String infocmp = InfoCmp.getInfoCmp(term);
            InfoCmp.parseInfoCmp(infocmp, bools, ints, strings);
            initialized = true;
        }
        Capability capability = Capability.byName(cap);
        if (capability != null) {
            String capStr = strings.get(capability);
            if (capStr != null) {
                StringWriter sw = new StringWriter();
                Curses.tputs(sw, capStr);
                return sw.toString();
            }
        }
    }
    catch (Exception e) {
        // Ignore
    }
    return defaultValue;
}
 
Example #5
Source File: DeviceBuilder.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public TerminalDevice build() {
    if(name == null)
        name = Config.isOSPOSIXCompatible() ? "ansi" : "windows";
    String data = getCapabilityFromType();
    TerminalDevice device = new TerminalDevice(name);

    if(data != null) {
        Set<Capability> bools = new HashSet<>();
        Map<Capability, Integer> ints = new HashMap<>();
        Map<Capability, String> strings = new HashMap<>();

        InfoCmp.parseInfoCmp(data, bools,ints, strings);
        device.addAllCapabilityBooleans(bools);
        device.addAllCapabilityInts(ints);
        device.addAllCapabilityStrings(strings);
    }

    return device;
}
 
Example #6
Source File: DeviceTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testWindowsCapabilities() throws Exception {
    Device device = DeviceBuilder.builder().name("windows").build();
    assertTrue( device.getBooleanCapability(Capability.move_standout_mode));
    assertEquals(8, device.getNumericCapability(Capability.max_colors).intValue());
    assertEquals(64, device.getNumericCapability(Capability.max_pairs).intValue());

    assertArrayEquals(new int[]{10}, device.getStringCapabilityAsInts(Capability.scroll_forward));
}
 
Example #7
Source File: BaseDevice.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override public boolean puts(Consumer<int[]> output, Capability capability) {
    String str = getStringCapability(capability);
    if (str == null) {
        return false;
    }
    output.accept(parseKeySeq(str));
    return true;
}
 
Example #8
Source File: BaseDevice.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public int[] getStringCapabilityAsInts(Capability capability) {
    String str = getStringCapability(capability);
    if(str != null)
        return parseKeySeq(str);
    else
        return null;
}
 
Example #9
Source File: Emacs.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public void remapKeysFromDevice(Device device) {
    //need to make sure we remap keys so we have the correct mapping
    remap(Key.HOME_2, device.getStringCapabilityAsInts(Capability.key_home));
    remap(Key.END_2, device.getStringCapabilityAsInts(Capability.key_end));
    remap(Key.UP, device.getStringCapabilityAsInts(Capability.key_up));
    remap(Key.DOWN, device.getStringCapabilityAsInts(Capability.key_down));
    remap(Key.LEFT, device.getStringCapabilityAsInts(Capability.key_left));
    remap(Key.RIGHT, device.getStringCapabilityAsInts(Capability.key_right));
    remap(Key.DELETE, device.getStringCapabilityAsInts(Capability.key_dc));
    remap(Key.CTRL_K, device.getStringCapabilityAsInts(Capability.key_dl));
    //remap(Key.HOME_2, device.getStringCapabilityAsInts(Capability.key_home));
}
 
Example #10
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
protected String getSequence(Capability cap) {
    String str = device.getStringCapability(cap);
    if (str != null) {
        StringWriter sw = new StringWriter();
        try {
            Curses.tputs(sw, str);
        } catch (IOException e) {
            throw new IOError(e);
        }
        return sw.toString();
    }
    return null;
}
 
Example #11
Source File: TelnetDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public int[] getStringCapabilityAsInts(Capability capability) {
    return new int[0];
}
 
Example #12
Source File: CliShell.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public boolean enableAlternateBuffer() {
    return connection.put(Capability.enter_ca_mode);
}
 
Example #13
Source File: ConsoleBufferTest.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean put(Capability capability, Object... params) {
    return false;
}
 
Example #14
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean put(Capability capability, Object... params) {
    return false;
}
 
Example #15
Source File: SSHDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean getBooleanCapability(Capability capability) {
    return bools.contains(capability);
}
 
Example #16
Source File: SSHDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getNumericCapability(Capability capability) {
    return ints.get(capability);
}
 
Example #17
Source File: SSHDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public String getStringCapability(Capability capability) {
    return strings.get(capability);
}
 
Example #18
Source File: TelnetDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean getBooleanCapability(Capability capability) {
    return false;
}
 
Example #19
Source File: TelnetDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Integer getNumericCapability(Capability capability) {
    return null;
}
 
Example #20
Source File: TelnetDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public String getStringCapability(Capability capability) {
    return null;
}
 
Example #21
Source File: DeviceTest.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Test
public void testXTermCapabilities() throws Exception {
    Device device = DeviceBuilder.builder().name("xterm-256color").build();
    Consumer<int[]> output = ints -> assertEquals("\u001B[H\u001B[2J", Parser.fromCodePoints(ints));
    device.puts(output, Capability.clear_screen);
}
 
Example #22
Source File: TelnetDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean puts(Consumer<int[]> output, Capability capability) {
    return false;
}
 
Example #23
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean put(Capability capability, Object... params) {
  return false;
}
 
Example #24
Source File: CLICommandInvocationBuilder.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean enableAlternateBuffer() {
    return console == null ? false : console.getConnection().put(Capability.enter_ca_mode);
}
 
Example #25
Source File: CLICommandInvocationBuilder.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean enableMainBuffer() {
    return console == null ? false : console.getConnection().put(Capability.exit_ca_mode);
}
 
Example #26
Source File: Vi.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void remapKeysFromDevice(Device device) {
    remap(Key.UP, device.getStringCapabilityAsInts(Capability.key_up));
    remap(Key.DOWN, device.getStringCapabilityAsInts(Capability.key_down));
}
 
Example #27
Source File: CliShell.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public boolean enableMainBuffer() {
    return connection.put(Capability.exit_ca_mode);
}
 
Example #28
Source File: CliShell.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void clear() {
    connection.put(Capability.clear_screen);
}
 
Example #29
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean put(Capability capability, Object... params) {
    return false;
}
 
Example #30
Source File: HttpDevice.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public boolean getBooleanCapability(Capability capability) {
    return bools.contains(capability);
}