本文整理汇总了Java中jline.console.UserInterruptException类的典型用法代码示例。如果您正苦于以下问题:Java UserInterruptException类的具体用法?Java UserInterruptException怎么用?Java UserInterruptException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInterruptException类属于jline.console包,在下文中一共展示了UserInterruptException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readLine
import jline.console.UserInterruptException; //导入依赖的package包/类
@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;
}
示例2: listen
import jline.console.UserInterruptException; //导入依赖的package包/类
/**
* コンソールからの入力のリスン
*
* @throws IOException I/O例外
*/
private void listen() throws IOException {
console.setPrompt("uroborosql > ");
console.setHandleUserInterrupt(true);
// コマンドのコード補完
console.addCompleter((buffer, cursor, candidates) -> {
String buff = buffer.trim();
if (buff.length() > 0 && !buffer.endsWith(" ") || buff.isEmpty()) {
Stream.of(Command.values()).filter(c -> c.match(buff)).map(Object::toString).forEach(candidates::add);
}
return candidates.isEmpty() ? -1 : 0;
});
// SQL名のコード補完
console.addCompleter(new SqlNameCompleter(config.getSqlManager().getSqlPathList()));
// バインドパラメータのコード補完
console.addCompleter(new BindParamCompleter());
// テーブル名のコード補完
console.addCompleter(new TableNameCompleter());
// SQLキーワードのコード補完
console.addCompleter(new SqlKeywordCompleter());
CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
handler.setPrintSpaceAfterFullCompletion(false);
console.setCompletionHandler(handler);
while (true) { // ユーザの一行入力を待つ
try {
String line = console.readLine();
if (!commandExecute(line)) {
break;
}
} catch (UserInterruptException uie) {
break;
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
示例3: readLine
import jline.console.UserInterruptException; //导入依赖的package包/类
@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);
}
}
示例4: onRun
import jline.console.UserInterruptException; //导入依赖的package包/类
@Inject(method = "run", at = @At("HEAD"), cancellable = true, remap = false)
private void onRun(CallbackInfo ci) {
final ConsoleReader reader = TerminalConsoleAppender.getReader();
if (reader != null) {
TerminalConsoleAppender.setFormatter(ConsoleFormatter::format);
reader.addCompleter(new ConsoleCommandCompleter());
reader.setPrompt("> ");
reader.setHandleUserInterrupt(true);
try {
String line;
while (!this.server.isServerStopped() && this.server.isServerRunning()) {
try {
line = reader.readLine();
if (line == null) {
break;
}
line = line.trim();
final String lineFinal = line;
if (!line.isEmpty()) {
this.server.addScheduledTask(() -> Canary.getServer().consoleCommand(lineFinal));
}
} catch (IOException e) {
Canary.log.error("Exception handling console input", e);
}
}
} catch (UserInterruptException exception) {
reader.shutdown();
Canary.commands().parseCommand(Canary.getServer(), "stop", new String[]{ "stop", "Ctrl-C", "at", "console" });
}
ci.cancel();
} else {
TerminalConsoleAppender.setFormatter(EnumChatFormatting::getTextWithoutFormattingCodes);
}
}
示例5: doDump
import jline.console.UserInterruptException; //导入依赖的package包/类
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);
}
}