Java Code Examples for org.jline.terminal.Terminal#handle()

The following examples show how to use org.jline.terminal.Terminal#handle() . 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: Query.java    From presto with Apache License 2.0 6 votes vote down vote up
public boolean renderOutput(Terminal terminal, PrintStream out, PrintStream errorChannel, OutputFormat outputFormat, boolean usePager, boolean showProgress)
{
    Thread clientThread = Thread.currentThread();
    SignalHandler oldHandler = terminal.handle(Signal.INT, signal -> {
        if (ignoreUserInterrupt.get() || client.isClientAborted()) {
            return;
        }
        client.close();
        clientThread.interrupt();
    });
    try {
        return renderQueryOutput(terminal, out, errorChannel, outputFormat, usePager, showProgress);
    }
    finally {
        terminal.handle(Signal.INT, oldHandler);
        Thread.interrupted(); // clear interrupt status
    }
}
 
Example 2
Source File: QueryPreprocessor.java    From presto with Apache License 2.0 6 votes vote down vote up
public static String preprocessQuery(Terminal terminal, Optional<String> catalog, Optional<String> schema, String query, List<String> preprocessorCommand, Duration timeout)
        throws QueryPreprocessorException
{
    Thread clientThread = Thread.currentThread();
    SignalHandler oldHandler = terminal.handle(Signal.INT, signal -> clientThread.interrupt());
    try {
        if (REAL_TERMINAL) {
            System.out.print(PREPROCESSING_QUERY_MESSAGE);
            System.out.flush();
        }
        return preprocessQueryInternal(catalog, schema, query, preprocessorCommand, timeout);
    }
    finally {
        if (REAL_TERMINAL) {
            System.out.print("\r" + Strings.repeat(" ", PREPROCESSING_QUERY_MESSAGE.length()) + "\r");
            System.out.flush();
        }
        terminal.handle(Signal.INT, oldHandler);
        Thread.interrupted(); // clear interrupt status
    }
}