jline.console.UserInterruptException Java Examples

The following examples show how to use jline.console.UserInterruptException. 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: LineReader.java    From sylph with Apache License 2.0 6 votes vote down vote up
@Override
public String readLine(String prompt, Character mask)
        throws IOException
{
    String line;
    interrupted = false;
    try {
        line = super.readLine(prompt, mask);
    }
    catch (UserInterruptException e) {
        interrupted = true;
        return null;
    }

    if (getHistory() instanceof Flushable) {
        ((Flushable) getHistory()).flush();
    }
    return line;
}
 
Example #2
Source File: JLineStringReader.java    From Latte-lang with MIT License 6 votes vote down vote up
@Override
public String read() throws Exception {
        if (reader == null) {
                initReader();
        }

        String line;
        while (true) {
                try {
                        line = reader.readLine();
                        break;
                } catch (UserInterruptException ignore) {
                        if (handler != null) {
                                handler.handle();
                        }
                }
        }
        if (line == null) return null;
        return line + '\n';
}
 
Example #3
Source File: ConsoleIOContext.java    From try-artifact with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String readLine(String prompt, String prefix) throws IOException, InputInterruptedException {
    this.prefix = prefix;
    try {
        return in.readLine(prompt);
    } catch (UserInterruptException ex) {
        throw (InputInterruptedException) new InputInterruptedException().initCause(ex);
    }
}
 
Example #4
Source File: Cqlsh.java    From sstable-tools with Apache License 2.0 4 votes vote down vote up
public void doDump(String command) throws Exception {
    if (sstables.isEmpty()) {
        System.out.println(MISSING_SSTABLES);
        return;
    }
    Query query;
    if (command.length() > 5) {
        query = getQuery("select * from sstables " + command.substring(5));
    } else {
        query = getQuery("select * from sstables");
    }

    console.setHistoryEnabled(false);
    AtomicInteger totalRows = new AtomicInteger(0);
    try (UnfilteredPartitionIterator scanner = query.getScanner()) {
        int limit = Integer.MAX_VALUE;
        if (query.statement.limit != null && !query.selection.isAggregate()) {
            limit = Integer.parseInt(query.statement.limit.getText());
        }
        AtomicInteger rowsPaged = new AtomicInteger(0);
        Function<Void, Void> deferToInput = o -> {
            if (paging && rowsPaged.get() >= pageSize) {
                rowsPaged.set(0);
                try {
                    String input = console.readLine(MORE, ' ');
                    if (input == null) {
                        totalRows.set(Integer.MAX_VALUE);
                    }
                } catch (UserInterruptException uie) {
                    // User interrupted, stop paging.
                    totalRows.set(Integer.MAX_VALUE);
                } catch (IOException e) {
                    System.err.println(errorMsg("Error while paging:" + e.getMessage()));
                }
            }
            return null;
        };

        while (scanner.hasNext() && totalRows.get() < limit) {
            UnfilteredRowIterator partition = scanner.next();
            deferToInput.apply(null);
            if (!partition.partitionLevelDeletion().isLive() && totalRows.get() < limit) {
                System.out.println("[" + metadata.getKeyValidator().getString(partition.partitionKey().getKey()) + "] " +
                        partition.partitionLevelDeletion());
                rowsPaged.incrementAndGet();
                totalRows.incrementAndGet();
            }
            deferToInput.apply(null);
            if (!partition.staticRow().isEmpty() && totalRows.get() < limit) {
                System.out.println(
                        "[" + metadata.getKeyValidator().getString(partition.partitionKey().getKey()) + "] " +
                                partition.staticRow().toString(metadata, true));
                rowsPaged.incrementAndGet();
                totalRows.incrementAndGet();
            }
            deferToInput.apply(null);
            while (partition.hasNext() && totalRows.get() < limit) {
                Unfiltered row = partition.next();
                System.out.println(
                        "[" + metadata.getKeyValidator().getString(partition.partitionKey().getKey()) + "] " +
                                row.toString(metadata, true));
                rowsPaged.incrementAndGet();
                totalRows.incrementAndGet();
                deferToInput.apply(null);
            }
        }
    } finally {
        if (totalRows.get() < Integer.MAX_VALUE) {
            System.out.printf("%n(%s rows)%n", totalRows.get());
        }
        console.setHistoryEnabled(true);
        console.setPrompt(prompt);
    }
}