Java Code Examples for org.aesh.terminal.Attributes#setLocalFlag()

The following examples show how to use org.aesh.terminal.Attributes#setLocalFlag() . 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: TestTerminalConnection.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignal() throws IOException, InterruptedException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(outputStream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    TerminalConnection connection = new TerminalConnection(Charset.defaultCharset(), pipedInputStream, out);
    Attributes attributes = new Attributes();
    attributes.setLocalFlag(Attributes.LocalFlag.ECHOCTL, true);
    connection.setAttributes(attributes);

    Readline readline = new Readline();
    readline.readline(connection, new Prompt(""), s -> {  });

    connection.openNonBlocking();
    outputStream.write(("FOO").getBytes());
    outputStream.flush();
    Thread.sleep(100);
    connection.getTerminal().raise(Signal.INT);
    connection.close();

    Assert.assertEquals("FOO^C"+ Config.getLineSeparator(), new String(out.toByteArray()));
}
 
Example 2
Source File: ExecPty.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private static void doParseLinuxOptions(String options, Attributes attributes) {
    String[] optionLines = options.split(Config.getLineSeparator());
    for(String line : optionLines)
        for(String option : line.trim().split(" ")) {
            //options starting with - are ignored
            option = option.trim();
            if(option.length() > 0 && option.charAt(0) != '-') {
                Attributes.ControlFlag controlFlag = getEnumFromString(Attributes.ControlFlag.class, option);
                if(controlFlag != null)
                    attributes.setControlFlag(controlFlag, true);
                else {
                    Attributes.InputFlag inputFlag = getEnumFromString(Attributes.InputFlag.class, option);
                    if(inputFlag != null)
                        attributes.setInputFlag(inputFlag, true);
                    else {
                        Attributes.LocalFlag localFlag = getEnumFromString(Attributes.LocalFlag.class, option);
                        if(localFlag != null)
                            attributes.setLocalFlag(localFlag, true);
                        else {
                            Attributes.OutputFlag outputFlag = getEnumFromString(Attributes.OutputFlag.class, option);
                            if(outputFlag != null)
                                attributes.setOutputFlag(outputFlag, true);
                        }
                    }
                }
            }
        }
}
 
Example 3
Source File: ReadlineConsole.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initializeConnection() throws IOException {
    if (connection == null) {
        connection = newConnection();
        pagingSupport = new PagingSupport(connection, readline, true);
        interruptHandler = signal -> {
            if (signal == Signal.INT) {
                LOG.trace("Calling InterruptHandler");
                connection.write(Config.getLineSeparator());
                // Put the console in closed state. No more readline
                // input handler can be set when closed.
                stop();
            }
        };
        connection.setSignalHandler(interruptHandler);
        // Do not display ^C
        Attributes attr = connection.getAttributes();
        attr.setLocalFlag(Attributes.LocalFlag.ECHOCTL, false);
        connection.setAttributes(attr);
        /**
         * On some terminal (Mac terminal), when the terminal switches to
         * the original mode (the mode in place prior readline is called
         * with echo ON) when executing a command, then, if there are still
         * some characters to read in the buffer (eg: large copy/paste of
         * commands) these characters are displayed by the terminal. It has
         * been observed on some platforms (eg: Mac OS). By entering the raw
         * mode we are not impacted by this behavior. That is tracked by
         * AESH-463.
         */
        connection.enterRawMode();
    }
}
 
Example 4
Source File: SSHAttributesBuilder.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public Attributes build() {
    Attributes attr = new Attributes();
    for (Map.Entry<PtyMode, Integer> e : environment.getPtyModes().entrySet()) {
        switch (e.getKey()) {
            case VINTR:
                attr.setControlChar(Attributes.ControlChar.VINTR, e.getValue());
                break;
            case VQUIT:
                attr.setControlChar(Attributes.ControlChar.VQUIT, e.getValue());
                break;
            case VERASE:
                attr.setControlChar(Attributes.ControlChar.VERASE, e.getValue());
                break;
            case VKILL:
                attr.setControlChar(Attributes.ControlChar.VKILL, e.getValue());
                break;
            case VEOF:
                attr.setControlChar(Attributes.ControlChar.VEOF, e.getValue());
                break;
            case VEOL:
                attr.setControlChar(Attributes.ControlChar.VEOL, e.getValue());
                break;
            case VEOL2:
                attr.setControlChar(Attributes.ControlChar.VEOL2, e.getValue());
                break;
            case VSTART:
                attr.setControlChar(Attributes.ControlChar.VSTART, e.getValue());
                break;
            case VSTOP:
                attr.setControlChar(Attributes.ControlChar.VSTOP, e.getValue());
                break;
            case VSUSP:
                attr.setControlChar(Attributes.ControlChar.VSUSP, e.getValue());
                break;
            case VDSUSP:
                attr.setControlChar(Attributes.ControlChar.VDSUSP, e.getValue());
                break;
            case VREPRINT:
                attr.setControlChar(Attributes.ControlChar.VREPRINT, e.getValue());
                break;
            case VWERASE:
                attr.setControlChar(Attributes.ControlChar.VWERASE, e.getValue());
                break;
            case VLNEXT:
                attr.setControlChar(Attributes.ControlChar.VLNEXT, e.getValue());
                break;
            case VSTATUS:
                attr.setControlChar(Attributes.ControlChar.VSTATUS, e.getValue());
                break;
            case VDISCARD:
                attr.setControlChar(Attributes.ControlChar.VDISCARD, e.getValue());
                break;
            case ECHO:
                attr.setLocalFlag(Attributes.LocalFlag.ECHO, e.getValue() != 0);
                break;
            case ICANON:
                attr.setLocalFlag(Attributes.LocalFlag.ICANON, e.getValue() != 0);
                break;
            case ISIG:
                attr.setLocalFlag(Attributes.LocalFlag.ISIG, e.getValue() != 0);
                break;
            case ICRNL:
                attr.setInputFlag(Attributes.InputFlag.ICRNL, e.getValue() != 0);
                break;
            case INLCR:
                attr.setInputFlag(Attributes.InputFlag.INLCR, e.getValue() != 0);
                break;
            case IGNCR:
                attr.setInputFlag(Attributes.InputFlag.IGNCR, e.getValue() != 0);
                break;
            case OCRNL:
                attr.setOutputFlag(Attributes.OutputFlag.OCRNL, e.getValue() != 0);
                break;
            case ONLCR:
                attr.setOutputFlag(Attributes.OutputFlag.ONLCR, e.getValue() != 0);
                break;
            case ONLRET:
                attr.setOutputFlag(Attributes.OutputFlag.ONLRET, e.getValue() != 0);
                break;
            case OPOST:
                attr.setOutputFlag(Attributes.OutputFlag.OPOST, e.getValue() != 0);
                break;
        }
    }

    return attr;
}