org.aesh.terminal.Attributes Java Examples

The following examples show how to use org.aesh.terminal.Attributes. 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: CliShell.java    From galleon with Apache License 2.0 6 votes vote down vote up
@Override
public Key read() throws InterruptedException {
    ActionDecoder decoder = new ActionDecoder();
    final Key[] key = {null};
    Attributes attributes = connection.enterRawMode();
    try {
        connection.setStdinHandler(keys -> {
            decoder.add(keys);
            if (decoder.hasNext()) {
                key[0] = Key.findStartKey(decoder.next().buffer().array());
                connection.stopReading();
            }
        });
        try {
            connection.openBlocking();
        } finally {
            connection.setStdinHandler(null);
        }
    } finally {
        connection.setAttributes(attributes);
    }
    return key[0];
}
 
Example #2
Source File: SignalTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomSignals() {

    Attributes attributes = new Attributes();
    attributes.setControlChar(Attributes.ControlChar.VEOF, Key.CTRL_A.getFirstValue());
    attributes.setControlChar(Attributes.ControlChar.VINTR, Key.CTRL_B.getFirstValue());
    TestConnection connection = new TestConnection(null, null, null, null, null, attributes, null);

    connection.setSignalHandler(signal -> {
        if(signal == Signal.INT)
            connection.write("INTR");
        else if(signal == Signal.EOF)
            connection.write("EOF");
    });

    connection.read("foo");
    assertEquals(": foo", connection.getOutputBuffer());
    connection.read(Key.CTRL_B);
    assertEquals(": fooINTR", connection.getOutputBuffer());
    connection.read(Key.CTRL_A);
    assertEquals(": fooINTREOF", connection.getOutputBuffer());
}
 
Example #3
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
private void checkAttributestLinux(Attributes attributes) {
    // -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc ixany imaxbel iutf8
    assertEquals(EnumSet.of(InputFlag.BRKINT, InputFlag.ICRNL, InputFlag.IXON, InputFlag.IXANY, InputFlag.IMAXBEL, InputFlag.IUTF8), attributes.getInputFlags());
    // opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
    assertEquals(EnumSet.of(OutputFlag.OPOST, OutputFlag.ONLCR), attributes.getOutputFlags());
    // -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
    assertEquals(EnumSet.of(ControlFlag.CREAD, ControlFlag.HUPCL, ControlFlag.CS8), attributes.getControlFlags());
    // isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
    assertEquals(EnumSet.of(LocalFlag.ISIG, LocalFlag.ICANON, LocalFlag.IEXTEN, LocalFlag.ECHO, LocalFlag.ECHOK, LocalFlag.ECHOCTL, LocalFlag.ECHOKE, LocalFlag.ECHOE), attributes.getLocalFlags());
    // intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0
    assertEquals(ExecPty.parseControlChar("^C"), attributes.getControlChar(ControlChar.VINTR));
    assertEquals(ExecPty.parseControlChar("^\\"), attributes.getControlChar(ControlChar.VQUIT));
    assertEquals(ExecPty.parseControlChar("^?"), attributes.getControlChar(ControlChar.VERASE));
    assertEquals(ExecPty.parseControlChar("^U"), attributes.getControlChar(ControlChar.VKILL));
    assertEquals(ExecPty.parseControlChar("^D"), attributes.getControlChar(ControlChar.VEOF));
    assertEquals(ExecPty.parseControlChar("M-^?"), attributes.getControlChar(ControlChar.VEOL));
    assertEquals(ExecPty.parseControlChar("M-^?"), attributes.getControlChar(ControlChar.VEOL2));
    assertEquals(ExecPty.parseControlChar("^Q"), attributes.getControlChar(ControlChar.VSTART));
    assertEquals(ExecPty.parseControlChar("^S"), attributes.getControlChar(ControlChar.VSTOP));
    assertEquals(ExecPty.parseControlChar("^Z"), attributes.getControlChar(ControlChar.VSUSP));
    assertEquals(ExecPty.parseControlChar("^R"), attributes.getControlChar(ControlChar.VREPRINT));
    assertEquals(ExecPty.parseControlChar("^W"), attributes.getControlChar(ControlChar.VWERASE));
    assertEquals(ExecPty.parseControlChar("^V"), attributes.getControlChar(ControlChar.VLNEXT));
    assertEquals(1, attributes.getControlChar(ControlChar.VMIN));
    assertEquals(0, attributes.getControlChar(ControlChar.VTIME));
}
 
Example #4
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 #5
Source File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public LineDisciplineTerminal(String name,
                              String type,
                              OutputStream masterOutput) throws IOException {
    super(name, type);
    PipedInputStream input = new LinePipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    // This is a hack to fix a problem in gogo where closure closes
    // streams for commands if they are instances of PipedInputStream.
    // So we need to get around and make sure it's not an instance of
    // that class by using a dumb FilterInputStream class to wrap it.
    this.slaveInput = new FilterInputStream(input) {};
    this.slaveOutput = new FilteringOutputStream();
    this.masterOutput = masterOutput;
    this.attributes = new Attributes();
    this.size = new Size(160, 50);
}
 
Example #6
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
private void checkAttributestUbuntu(Attributes attributes) {
    // -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
    assertEquals(EnumSet.of(InputFlag.ICRNL, InputFlag.IXON, InputFlag.IUTF8), attributes.getInputFlags());
    // opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
    assertEquals(EnumSet.of(OutputFlag.OPOST, OutputFlag.ONLCR), attributes.getOutputFlags());
    // -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
    assertEquals(EnumSet.of(ControlFlag.CREAD, ControlFlag.CS8), attributes.getControlFlags());
    // isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
    assertEquals(EnumSet.of(LocalFlag.ISIG, LocalFlag.ICANON, LocalFlag.IEXTEN, LocalFlag.ECHO, LocalFlag.ECHOK, LocalFlag.ECHOCTL, LocalFlag.ECHOKE, LocalFlag.ECHOE), attributes.getLocalFlags());
    // intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0
    assertEquals(ExecPty.parseControlChar("^C"), attributes.getControlChar(ControlChar.VINTR));
    assertEquals(ExecPty.parseControlChar("^\\"), attributes.getControlChar(ControlChar.VQUIT));
    assertEquals(ExecPty.parseControlChar("^?"), attributes.getControlChar(ControlChar.VERASE));
    assertEquals(ExecPty.parseControlChar("^U"), attributes.getControlChar(ControlChar.VKILL));
    assertEquals(ExecPty.parseControlChar("^D"), attributes.getControlChar(ControlChar.VEOF));
    assertEquals(-1, attributes.getControlChar(ControlChar.VEOL));
    assertEquals(-1, attributes.getControlChar(ControlChar.VEOL2));
    assertEquals(ExecPty.parseControlChar("^Q"), attributes.getControlChar(ControlChar.VSTART));
    assertEquals(ExecPty.parseControlChar("^S"), attributes.getControlChar(ControlChar.VSTOP));
    assertEquals(ExecPty.parseControlChar("^Z"), attributes.getControlChar(ControlChar.VSUSP));
    assertEquals(ExecPty.parseControlChar("^R"), attributes.getControlChar(ControlChar.VREPRINT));
    assertEquals(ExecPty.parseControlChar("^W"), attributes.getControlChar(ControlChar.VWERASE));
    assertEquals(ExecPty.parseControlChar("^V"), attributes.getControlChar(ControlChar.VLNEXT));
    assertEquals(1, attributes.getControlChar(ControlChar.VMIN));
    assertEquals(0, attributes.getControlChar(ControlChar.VTIME));
}
 
Example #7
Source File: AbstractTerminal.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
protected void echoSignal(Signal signal) {
    Attributes.ControlChar cc = null;
    switch (signal) {
        case INT:
            cc = Attributes.ControlChar.VINTR;
            break;
        case QUIT:
            cc = Attributes.ControlChar.VQUIT;
            break;
        case SUSP:
            cc = Attributes.ControlChar.VSUSP;
            break;
    }
    if (cc != null) {
        int vcc = getAttributes().getControlChar(cc);
        if (vcc > 0 && vcc < 32) {
            try {
                output().write(new String(new char[]{'^', (char) (vcc + '@')}).getBytes());
            }
            catch (IOException e) {
                LOGGER.log(Level.WARNING, "Failed to write out ^(C) - or other signals", e);
            }
        }
    }
}
 
Example #8
Source File: ExecPty.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Override
public Attributes getAttr() throws IOException {
    try {
        String cfg = doGetConfig();
        if (OSUtils.IS_HPUX || OSUtils.IS_SUNOS) {
            return doGetAttr(cfg);
        }
        else if(OSUtils.IS_LINUX) {
            return doGetLinuxAttr(cfg);
        }
         else
            return doGetAttr(cfg);
    }
    catch(IOException ioe) {
        //if we get permission denied on stty -F tty -a we can try without -F tty
        if(ioe.getMessage().contains("Permission denied")) {
           return doGetAttr(doGetFailSafeConfig());
        }
        else
            throw ioe;
    }
}
 
Example #9
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseAttributesHpux() throws IOException {
    Attributes attributes = ExecPty.doGetAttr(hpuxSttySample);
    // -ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc ixon ixany -ixoff -imaxbel -rtsxoff -ctsxon -ienqak
    assertEquals(EnumSet.of(InputFlag.BRKINT, InputFlag.IGNPAR, InputFlag.ISTRIP, InputFlag.ICRNL, InputFlag.IXON, InputFlag.IXANY), attributes.getInputFlags());
    // opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel -tostop
    assertEquals(EnumSet.of(OutputFlag.OPOST, OutputFlag.ONLCR), attributes.getOutputFlags());
    // -parenb -parodd cs8 -cstopb hupcl cread -clocal -loblk -crts
    assertEquals(EnumSet.of(ControlFlag.CREAD, ControlFlag.CS8, ControlFlag.HUPCL), attributes.getControlFlags());
    // isig icanon -iexten -xcase echo -echoe echok -echonl -noflsh -echoctl -echoprt -echoke -flusho -pendin
    assertEquals(EnumSet.of(LocalFlag.ISIG, LocalFlag.ICANON, LocalFlag.ECHO, LocalFlag.ECHOK), attributes.getLocalFlags());
    // min = 4; time = 0; intr = DEL; quit = ^\\; erase = #; kill = @; eof = ^D; eol = ^@; eol2 <undef>; swtch = ^@; stop = ^S; start = ^Q; susp <undef>; dsusp <undef>; werase <undef>; lnext <undef>;
    assertEquals(127, attributes.getControlChar(ControlChar.VINTR));
    assertEquals(ExecPty.parseControlChar("^\\"), attributes.getControlChar(ControlChar.VQUIT));
    assertEquals('#', attributes.getControlChar(ControlChar.VERASE));
    assertEquals('@', attributes.getControlChar(ControlChar.VKILL));
    assertEquals(ExecPty.parseControlChar("^D"), attributes.getControlChar(ControlChar.VEOF));
    assertEquals(0, attributes.getControlChar(ControlChar.VEOL));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VEOL2));
    assertEquals(ExecPty.parseControlChar("^Q"), attributes.getControlChar(ControlChar.VSTART));
    assertEquals(ExecPty.parseControlChar("^S"), attributes.getControlChar(ControlChar.VSTOP));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VSUSP));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VREPRINT));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VWERASE));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VLNEXT));
    assertEquals(4, attributes.getControlChar(ControlChar.VMIN));
    assertEquals(0, attributes.getControlChar(ControlChar.VTIME));
}
 
Example #10
Source File: HttpTtyConnection.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public HttpTtyConnection(Charset charset, Size size) {
    this.charset = charset;
    this.size = size;
    this.eventDecoder = new EventDecoder(3, 4, 26);
    this.decoder = new Decoder(512, charset, eventDecoder);
    this.stdout = new TtyOutputMode(new Encoder(charset, this::write));

    this.device = new HttpDevice("vt100");
    attributes = new Attributes();
}
 
Example #11
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseAttributesSolaris() throws IOException {
    Attributes attributes = ExecPty.doGetAttr(solarisSttySample);
    // -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc ixon ixany -ixoff imaxbel
    assertEquals(EnumSet.of(InputFlag.BRKINT, InputFlag.ICRNL, InputFlag.IXON, InputFlag.IXANY, InputFlag.IMAXBEL), attributes.getInputFlags());
    // opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3
    assertEquals(EnumSet.of(OutputFlag.OPOST, OutputFlag.ONLCR), attributes.getOutputFlags());
    // -parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk -crtscts -crtsxoff -parext
    assertEquals(EnumSet.of(ControlFlag.CREAD, ControlFlag.CS8), attributes.getControlFlags());
    // isig icanon -xcase echo echoe echok -echonl -noflsh -tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten
    assertEquals(EnumSet.of(LocalFlag.ISIG, LocalFlag.ICANON, LocalFlag.IEXTEN, LocalFlag.ECHO, LocalFlag.ECHOK, LocalFlag.ECHOCTL, LocalFlag.ECHOKE, LocalFlag.ECHOE), attributes.getLocalFlags());
    // intr = ^c; quit = ^\\; erase = ^?; kill = ^u; eof = ^d; eol = -^?; eol2 = -^?; swtch = <undef>; start = ^q; stop = ^s; susp = ^z; dsusp = ^y; rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;
    assertEquals(ExecPty.parseControlChar("^C"), attributes.getControlChar(ControlChar.VINTR));
    assertEquals(ExecPty.parseControlChar("^\\"), attributes.getControlChar(ControlChar.VQUIT));
    assertEquals(ExecPty.parseControlChar("^?"), attributes.getControlChar(ControlChar.VERASE));
    assertEquals(ExecPty.parseControlChar("^U"), attributes.getControlChar(ControlChar.VKILL));
    assertEquals(ExecPty.parseControlChar("^D"), attributes.getControlChar(ControlChar.VEOF));
    assertEquals(ExecPty.parseControlChar("-^?"), attributes.getControlChar(ControlChar.VEOL));
    assertEquals(ExecPty.parseControlChar("-^?"), attributes.getControlChar(ControlChar.VEOL2));
    assertEquals(ExecPty.parseControlChar("^Q"), attributes.getControlChar(ControlChar.VSTART));
    assertEquals(ExecPty.parseControlChar("^S"), attributes.getControlChar(ControlChar.VSTOP));
    assertEquals(ExecPty.parseControlChar("^Z"), attributes.getControlChar(ControlChar.VSUSP));
    assertEquals(ExecPty.parseControlChar("^R"), attributes.getControlChar(ControlChar.VREPRINT));
    assertEquals(ExecPty.parseControlChar("^W"), attributes.getControlChar(ControlChar.VWERASE));
    assertEquals(ExecPty.parseControlChar("^V"), attributes.getControlChar(ControlChar.VLNEXT));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VMIN));
    //assertEquals(-1, attributes.getControlChar(ControlChar.VTIME));
}
 
Example #12
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public AbstractWindowsTerminal(boolean consumeCP, OutputStream output, String name, boolean nativeSignals, SignalHandler signalHandler) throws IOException {
    super(name, "windows", signalHandler);
    PipedInputStream input = new PipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    this.input = new FilterInputStream(input) {};
    this.cpConsumer = consumeCP ? new ConsoleOutput() : null;
    this.output = output;
    String encoding = getConsoleEncoding();
    if (encoding == null) {
        encoding = Charset.defaultCharset().name();
    }
    this.writer = new PrintWriter(new OutputStreamWriter(this.output, encoding));
    // Attributes
    attributes.setLocalFlag(Attributes.LocalFlag.ISIG, true);
    attributes.setControlChar(Attributes.ControlChar.VINTR, ctrl('C'));
    attributes.setControlChar(Attributes.ControlChar.VEOF,  ctrl('D'));
    attributes.setControlChar(Attributes.ControlChar.VSUSP, ctrl('Z'));
    // Handle signals
    if (nativeSignals) {
        for (final Signal signal : Signal.values()) {
            nativeHandlers.put(signal,
                    Signals.register(signal.name(), () -> raise(signal)));
        }
    }
    pump = new Thread(this::pump, "WindowsStreamPump");
    pump.setDaemon(true);
    pump.start();
    closer = this::close;
    ShutdownHooks.add(closer);
}
 
Example #13
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Attributes getAttributes() {
    int mode = getConsoleMode();
    if ((mode & ENABLE_ECHO_INPUT) != 0) {
        attributes.setLocalFlag(Attributes.LocalFlag.ECHO, true);
    }
    if ((mode & ENABLE_LINE_INPUT) != 0) {
        attributes.setLocalFlag(Attributes.LocalFlag.ICANON, true);
    }
    return new Attributes(attributes);
}
 
Example #14
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public void setAttributes(Attributes attr) {
    attributes.copy(attr);
    int mode = 0;
    if (attr.getLocalFlag(Attributes.LocalFlag.ECHO)) {
        mode |= ENABLE_ECHO_INPUT;
    }
    if (attr.getLocalFlag(Attributes.LocalFlag.ICANON)) {
        mode |= ENABLE_LINE_INPUT;
    }
    setConsoleMode(mode);
}
 
Example #15
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private void processInputByte(byte[] buf) throws IOException {
    for(byte b : buf) {
        int c = b;
        if (attributes.getLocalFlag(Attributes.LocalFlag.ISIG)) {
            if (c == attributes.getControlChar(Attributes.ControlChar.VINTR)) {
                raise(Signal.INT);
            }
            else if (c == attributes.getControlChar(Attributes.ControlChar.VQUIT)) {
                raise(Signal.QUIT);
            }
            else if (c == attributes.getControlChar(Attributes.ControlChar.VSUSP)) {
                raise(Signal.SUSP);
            }
            else if (c == attributes.getControlChar(Attributes.ControlChar.VSTATUS)) {
                raise(Signal.INFO);
            }
        }
        if (c == '\r') {
            if (attributes.getInputFlag(Attributes.InputFlag.ICRNL)) {
                slaveInputPipe.write('\n');
            }
            else
                slaveInputPipe.write(c);
        }
        else if (c == '\n' && attributes.getInputFlag(Attributes.InputFlag.INLCR)) {
            slaveInputPipe.write('\r');
        }
        else {
            slaveInputPipe.write(c);
        }
    }
    slaveInputPipe.flush();
}
 
Example #16
Source File: WinExternalTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public WinExternalTerminal(String name, String type, InputStream masterInput, OutputStream masterOutput) throws IOException {
    super(name, type, masterInput, masterOutput);
    Attributes attributes = new Attributes();
    attributes.setInputFlag(Attributes.InputFlag.IGNCR, true);
    attributes.setInputFlag(Attributes.InputFlag.ICRNL, true);
    setAttributes(attributes);
}
 
Example #17
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptimizedParseAttributesUbuntu() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        Attributes attributes = ExecPty.doGetLinuxAttr(ubuntuSttySample);
        checkAttributestUbuntu(attributes);
    }
}
 
Example #18
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseAttributesUbuntu() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        Attributes attributes = ExecPty.doGetAttr(ubuntuSttySample);
        checkAttributestUbuntu(attributes);
    }
}
 
Example #19
Source File: ExecPtyTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptimizedParseAttributesLinux() throws IOException {
    if(Config.isOSPOSIXCompatible()) {
        Attributes attributes = ExecPty.doGetLinuxAttr(linuxSttySample);
        checkAttributestLinux(attributes);
    }
}
 
Example #20
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 #21
Source File: ExecPty.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
static Attributes doGetLinuxAttr(String cfg) {
    Attributes attributes = new Attributes();
    String[] attr = cfg.split(";");
    //the first line of attributes we ignore (speed, rows, columns and line)
    //the rest which are delimited with ; are control cars
    setAttr(Attributes.ControlChar.VINTR, attr[4], attributes);
    setAttr(Attributes.ControlChar.VQUIT, attr[5], attributes);
    setAttr(Attributes.ControlChar.VERASE, attr[6], attributes);
    setAttr(Attributes.ControlChar.VKILL, attr[7], attributes);
    setAttr(Attributes.ControlChar.VEOF, attr[8], attributes);
    setAttr(Attributes.ControlChar.VEOL, attr[9], attributes);
    setAttr(Attributes.ControlChar.VEOL2, attr[10], attributes);
    //setAttr(Attributes.ControlChar.VSWTC, attr[11], attributes);
    setAttr(Attributes.ControlChar.VSTART, attr[12], attributes);
    setAttr(Attributes.ControlChar.VSTOP, attr[13], attributes);
    setAttr(Attributes.ControlChar.VSUSP, attr[14], attributes);
    setAttr(Attributes.ControlChar.VREPRINT, attr[15], attributes);
    setAttr(Attributes.ControlChar.VWERASE, attr[16], attributes);
    setAttr(Attributes.ControlChar.VLNEXT, attr[17], attributes);
    setAttr(Attributes.ControlChar.VDISCARD, attr[18], attributes);
    setAttr(Attributes.ControlChar.VMIN, attr[19], attributes);
    setAttr(Attributes.ControlChar.VTIME, attr[20], attributes);

    doParseLinuxOptions(attr[21], attributes);

    return attributes;
}
 
Example #22
Source File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
/**
 * Master output processing.
 * All data going to the master should be provided by this method.
 *
 * @param c the output byte
 * @throws IOException
 */
protected void processOutputByte(int c) throws IOException {
    if (attributes.getOutputFlag(Attributes.OutputFlag.OPOST)) {
        if (c == '\n') {
            if (attributes.getOutputFlag(Attributes.OutputFlag.ONLCR)) {
                masterOutput.write('\r');
                masterOutput.write('\n');
                return;
            }
        }
    }
    masterOutput.write(c);
}
 
Example #23
Source File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private void doProcessInputByte(int c) throws IOException {
           if (attributes.getLocalFlag(Attributes.LocalFlag.ISIG)) {
        if (c == attributes.getControlChar(Attributes.ControlChar.VINTR)) {
            raise(Signal.INT);
            return;
        } else if (c == attributes.getControlChar(Attributes.ControlChar.VQUIT)) {
            raise(Signal.QUIT);
            return;
        } else if (c == attributes.getControlChar(Attributes.ControlChar.VSUSP)) {
            raise(Signal.SUSP);
            return;
        } else if (c == attributes.getControlChar(Attributes.ControlChar.VSTATUS)) {
            raise(Signal.INFO);
        }
    }
    if (c == '\r') {
        if (attributes.getInputFlag(Attributes.InputFlag.IGNCR)) {
            return;
        }
        if (attributes.getInputFlag(Attributes.InputFlag.ICRNL)) {
            c = '\n';
        }
    } else if (c == '\n' && attributes.getInputFlag(Attributes.InputFlag.INLCR)) {
        c = '\r';
    }
    if (attributes.getLocalFlag(Attributes.LocalFlag.ECHO)) {
        processOutputByte(c);
        masterOutput.flush();
    }
    slaveInputPipe.write(c);
}
 
Example #24
Source File: AbstractPosixTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public void setAttributes(Attributes attr) {
    try {
        pty.setAttr(attr);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #25
Source File: AbstractPosixTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Attributes getAttributes() {
    try {
        return pty.getAttr();
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #26
Source File: TelnetTtyConnection.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
protected void onOpen(TelnetConnection conn) {
  this.conn = conn;

  //set default size for now
    size = new Size(80, 24);

  // Kludge mode
  conn.writeWillOption(Option.ECHO);
  conn.writeWillOption(Option.SGA);

  //
  if (inBinary) {
    conn.writeDoOption(Option.BINARY);
  }
  if (outBinary) {
    conn.writeWillOption(Option.BINARY);
  }

  // Window size
  conn.writeDoOption(Option.NAWS);

  // Get some info about user
  conn.writeDoOption(Option.TERMINAL_TYPE);

  attributes = new Attributes();

  //
  checkAccept();
}
 
Example #27
Source File: ReadlineConsole.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setAttributes(Attributes attr) {
    // Console already closed with Ctrl-c,
    // aesh AeshInputProcessor.finish would reset the attributes
    // to original ones, in our case we are in raw (AESH-463) so
    // ignore these attributes. During connection.close the original
    // attributes have been set back by the connection.
    if (!console.closed) {
        super.setAttributes(attr);
    }
}
 
Example #28
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 #29
Source File: ConsoleBufferTest.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Attributes getAttributes() {
    return null;
}
 
Example #30
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public Attributes getAttributes() {
    return attributes;
}