Search in sources :

Example 1 with Signal

use of org.jline.terminal.Terminal.Signal in project flink by apache.

the class CliView method prepareTerminal.

private Tuple2<Attributes, Map<Signal, SignalHandler>> prepareTerminal() {
    final Terminal terminal = client.getTerminal();
    final Attributes prevAttributes = terminal.getAttributes();
    // adopted from org.jline.builtins.Nano
    // see also
    // https://en.wikibooks.org/wiki/Serial_Programming/termios#Basic_Configuration_of_a_Serial_Interface
    // no line processing
    // canonical mode off, echo off, echo newline off, extended input processing off
    Attributes newAttr = new Attributes(prevAttributes);
    newAttr.setLocalFlags(EnumSet.of(LocalFlag.ICANON, LocalFlag.ECHO, LocalFlag.IEXTEN), false);
    // turn off input processing
    newAttr.setInputFlags(EnumSet.of(Attributes.InputFlag.IXON, Attributes.InputFlag.ICRNL, Attributes.InputFlag.INLCR), false);
    // one input byte is enough to return from read, inter-character timer off
    newAttr.setControlChar(Attributes.ControlChar.VMIN, 1);
    newAttr.setControlChar(Attributes.ControlChar.VTIME, 0);
    newAttr.setControlChar(Attributes.ControlChar.VINTR, 0);
    terminal.setAttributes(newAttr);
    final Map<Signal, SignalHandler> prevSignals = new HashMap<>();
    prevSignals.put(Signal.WINCH, terminal.handle(Signal.WINCH, this::handleSignal));
    prevSignals.put(Signal.INT, terminal.handle(Signal.INT, this::handleSignal));
    prevSignals.put(Signal.QUIT, terminal.handle(Signal.QUIT, this::handleSignal));
    return Tuple2.of(prevAttributes, prevSignals);
}
Also used : Signal(org.jline.terminal.Terminal.Signal) HashMap(java.util.HashMap) Attributes(org.jline.terminal.Attributes) SignalHandler(org.jline.terminal.Terminal.SignalHandler) Terminal(org.jline.terminal.Terminal)

Aggregations

HashMap (java.util.HashMap)1 Attributes (org.jline.terminal.Attributes)1 Terminal (org.jline.terminal.Terminal)1 Signal (org.jline.terminal.Terminal.Signal)1 SignalHandler (org.jline.terminal.Terminal.SignalHandler)1