本文整理汇总了Java中org.jline.reader.UserInterruptException类的典型用法代码示例。如果您正苦于以下问题:Java UserInterruptException类的具体用法?Java UserInterruptException怎么用?Java UserInterruptException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInterruptException类属于org.jline.reader包,在下文中一共展示了UserInterruptException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDoubleValue
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
protected Double getDoubleValue() {
Double value = null;
while (value == null) {
String line;
try {
line = reader.readLine(prompt()).trim();
} catch (EndOfFileException | UserInterruptException e) {
break;
}
if (line.isEmpty()) {
logger.info("no value entered");
break;
}
try {
value = Double.valueOf(line);
} catch (NumberFormatException nfe) {
PrintWriter writer = terminal.writer();
writer.println("please enter a number");
}
}
return value;
}
示例2: getIntValue
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
protected Integer getIntValue() {
Integer value = null;
while (value == null) {
String line;
try {
line = reader.readLine(prompt()).trim();
} catch (EndOfFileException | UserInterruptException e) {
break;
}
if (line.isEmpty()) {
logger.info("no value entered");
break;
}
try {
value = Integer.valueOf(line);
} catch (NumberFormatException nfe) {
terminal.writer().println("please enter an integer");
}
}
return value;
}
示例3: login
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
private void login(String username, String code, Settings settings) {
printBanner();
LineReader reader = ShellUtils.lineReader(null, Optional.empty());
try {
if (username == null) {
username = reader.readLine(getPrompt("Username"));
}
String password = reader.readLine(getPrompt("Password"), new Character('*'));
postForTokenAndHandleResponse(username, password, code, settings, reader);
}
catch (EndOfFileException | UserInterruptException e) {
log.error("Canceled!");
}
finally {
ShellUtils.shutdown(reader);
}
}
示例4: readLine
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
/**
* Attempt to read a logical line of input from the user. Can span multiple physical lines, as
* long as all but the last end with '\\'.
* @return The parsed, logical line.
* @throws EndOfFileException If there is no more input available from the user.
* @throws IOException If any other I/O error occurs.
*/
private String readLine() throws IOException {
while (true) {
try {
String result = terminal.getLineReader().readLine();
// A 'dumb' terminal (the kind used at runtime if a 'system' terminal isn't available) will
// return null on EOF and user interrupt, instead of throwing the more fine-grained
// exceptions. This null-check helps ensure that, upon encountering EOF, even a 'dumb'
// terminal will be able to exit intelligently.
if (result == null) {
throw new EndOfFileException();
} else {
return result.trim();
}
} catch (UserInterruptException exception) {
// User hit ctrl-C, just clear the current line and try again.
terminal.writer().println("^C");
terminal.flush();
}
}
}
示例5: readLine
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public String readLine() throws IOException {
try {
// Ignore the line that will be read, in order to process multiline commands in the client code.
reader.readLine(InteractiveModeConstants.PROMPT);
// Return the raw line.
return reader.getParsedLine().line();
} catch (UserInterruptException | EndOfFileException e) {
return null;
}
}
示例6: getFwdRevDoubles
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
protected double[] getFwdRevDoubles() {
terminal
.writer()
.println(Messages.bold("\nenter <forward>,<reverse> or a single number for both"));
double[] values = null;
while (values == null) {
String line;
try {
line = reader.readLine(prompt()).trim();
} catch (EndOfFileException | UserInterruptException e) {
break;
}
if (line.isEmpty()) {
logger.info("{}: no value entered", name());
break;
}
List<String> entries = Arrays.asList(line.split(","));
double[] doubles = new double[2];
try {
if (entries.size() > 0) {
doubles[0] = Double.valueOf(entries.get(0));
} else {
help();
continue;
}
if (entries.size() > 1) {
doubles[1] = Double.valueOf(entries.get(1));
} else {
doubles[1] = doubles[0] * (flipReverse ? -1 : 1);
}
} catch (NumberFormatException nfe) {
help();
continue;
}
values = doubles;
}
return values;
}
示例7: getBooleanValue
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
protected Boolean getBooleanValue() {
Boolean value = null;
while (value == null) {
String line;
try {
line = reader.readLine(Messages.prompt("configure " + name() + " (Y/N)> ")).trim();
} catch (EndOfFileException | UserInterruptException e) {
break;
}
if (line.isEmpty()) {
logger.info("no value entered");
break;
}
boolean setpoint;
if (line.equalsIgnoreCase("Y")) {
setpoint = true;
} else if (line.equalsIgnoreCase("N")) {
setpoint = false;
} else {
terminal.writer().println(Messages.boldRed("enter <Y>, <N> or <enter> to go back"));
continue;
}
value = setpoint;
}
return value;
}
示例8: perform
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public void perform() {
if (servoSet.getServo() == null) {
terminal.writer().println(Messages.boldRed("no servo selected"));
return;
}
terminal.writer().println(Messages.bold("Enter servo setpoint, press <enter> to go back"));
while (true) {
String line;
try {
line = reader.readLine(Messages.prompt("setpoint or <return> or b/B to exit> ")).trim();
} catch (EndOfFileException | UserInterruptException e) {
continue;
}
if (line.isEmpty() || line.equalsIgnoreCase("b")) {
return;
}
double setpoint;
try {
setpoint = Double.valueOf(line);
} catch (NumberFormatException nfe) {
terminal.writer().println(Messages.boldRed("please enter a number"));
continue;
}
terminal.writer().print(Messages.bold(String.format("setting servo to %.2f%n", setpoint)));
servoSet.getServo().set(setpoint);
}
}
示例9: perform
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public void perform() {
if (dioSet.getDigitalOutput() == null) {
terminal.writer().println(Messages.boldRed("no digital output selected selected"));
return;
}
terminal.writer().println(Messages.bold("Enter duty cycle, press <enter> to go back"));
while (true) {
String line;
try {
line = reader.readLine(Messages.prompt("number or <return> to exit> ")).trim();
} catch (EndOfFileException | UserInterruptException e) {
continue;
}
if (line.isEmpty()) {
return;
}
double setpoint;
try {
setpoint = Double.valueOf(line);
} catch (NumberFormatException nfe) {
help();
continue;
}
terminal.writer().print(Messages.bold(String.format("pulsing for %.2f%n", setpoint)));
DigitalOutput digitalOutput = dioSet.getDigitalOutput();
digitalOutput.disablePWM();
digitalOutput.enablePWM(setpoint);
}
}
示例10: perform
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public void perform() {
if (dioSet.getDigitalOutput() == null) {
terminal.writer().println(Messages.boldRed("no digital output selected selected"));
return;
}
terminal
.writer()
.println(Messages.bold("Enter 0 for off or 1 for on, press <enter> to go back"));
while (true) {
String line;
try {
line = reader.readLine(Messages.prompt("0/1 or <return> or b/B to exit> ")).trim();
} catch (EndOfFileException | UserInterruptException e) {
continue;
}
if (line.isEmpty() || line.equalsIgnoreCase("b")) {
return;
}
int setpoint;
try {
setpoint = Integer.valueOf(line);
} catch (NumberFormatException nfe) {
help();
continue;
}
if (setpoint != 0 && setpoint != 1) {
help();
continue;
}
terminal.writer().print(Messages.bold(String.format("setting dio to %d%n", setpoint)));
dioSet.getDigitalOutput().set(setpoint == 1);
}
}
示例11: perform
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public void perform() {
if (dioSet.getDigitalOutput() == null) {
terminal.writer().println(Messages.boldRed("no digital output selected selected"));
return;
}
terminal.writer().println(Messages.bold("Enter pulse length, press <enter> to go back"));
while (true) {
String line;
try {
line = reader.readLine(Messages.prompt("number or <return> to exit> ")).trim();
} catch (EndOfFileException | UserInterruptException e) {
continue;
}
if (line.isEmpty()) {
return;
}
double setpoint;
try {
setpoint = Double.valueOf(line);
} catch (NumberFormatException nfe) {
help();
continue;
}
terminal.writer().print(Messages.bold(String.format("pulsing for %.2f%n", setpoint)));
dioSet.getDigitalOutput().pulse(setpoint);
}
}
示例12: readCommandLine
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public String readCommandLine() {
try {
String prompt = toAnsi(getCommandPrompt());
return commandReader.readLine(prompt);
} catch (UserInterruptException e) {
if (confirmQuit()) {
throw new ConsoleTerminatedException();
} else {
return null;
}
}
}
示例13: readLine
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public String readLine(String prompt) {
try {
return reader.readLine(prompt);
} catch (UserInterruptException e) {
throw new ConsoleTerminatedException();
}
}
示例14: readPassword
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
@Override
public String readPassword(String prompt) {
try {
return reader.readLine(prompt, MASK_CHAR);
} catch (UserInterruptException e) {
throw new ConsoleTerminatedException();
}
}
示例15: start
import org.jline.reader.UserInterruptException; //导入依赖的package包/类
public void start() {
logger.log("\n" +
" \n" +
" ╓╖╓\n" +
" ╓▓▓▓▓▓M▌ ╟╜▀▓▌╗╥ █\n" +
" ▓▓▓▓▓¼▓▓▓╗╬╢╬▓▓▓▌╗, ,, ,; ,;;\n" +
" ╓▓▓╩╬▌╬▓▓▓▓╟▓▓▓▓▓▓▓▓▓▌ █▄▀╙└╙▀█▄ ▄▀▀└└\"▀█ ▄█▀┘└└▀▀▄ █▀ █\n" +
" ▓▓▌w╬▓▓▓▓▓╡▓▓▓▓▓▓▓▓▓▓▓M █▌ █ █▀ █ █▀ \"█ █▀ █\n" +
" ▐▓▓▓,╟▓▓▓▓▓▓╟▓▓▓▓▓▓▓▓▓▓ █= █ █▀▀▀▀▀▀▀▀▀ █ █⌐ █▀ ╓ █\n" +
" ▐▓▓▓▄,▓▓▓▓▓▓▓╬╬▓▓▓▓▓▓▌⌐ █= █ ╙█ ╙█ ▄▀ █▀ █= █\n" +
" ╟▓▓▓Ü ╟▓▌╬▓▓▓▓╬▌╝╬╬▓▌ ▀⌐ █ `▀Wæ▄æA▀ ▀▀æ▄æΦ▀└ ╝█≡≡≡≡≡≡█= █\n" +
" ╚▓▓▌▌╬▓▓▓▓▌▀▓╜½╖▓▓M █= █\n" +
" `╚▓▓▓▓▓▓▓▓▓╟@╬▓▀ ▀⌐╘≡▀└\n" +
" ▓▓▓▓▓▓▓▓▓╜╙`\n" +
" ╚▓▓▓▓▓▀\n" +
"\n", AttributedStyle.BOLD.foreground(GREEN));
AttributedStyle warningStyle = AttributedStyle.BOLD.blink().foreground(YELLOW);
logger.log("");
logger.log("Initializing session now...", AttributedStyle.DEFAULT.italic());
session.init(this.getClass().getResourceAsStream("/exercises/dump.cypher"));
logger.log("... done!", AttributedStyle.DEFAULT.italic());
logger.log("");
logger.log("Welcome to Devoxx France 2017 Hands on Neo4j!");
logger.log("Available commands can be displayed with ':commands'");
logger.log("");
logger.log("Please make sure your Cypher statements end with a semicolon.", warningStyle);
logger.log("Every exercise is independent, no changes are persisted against your database.", warningStyle);
logger.log("Make sure to undo the insertions in the browser before using this REPL!", warningStyle);
logger.log("");
logger.log("Ask for help when needed and have fun!", AttributedStyle.BOLD.foreground(AttributedStyle.CYAN));
while (true) {
try {
String statement = lineReader.readLine("(:Devoxx)-[:`<3`]-(:Cypher)> ");
commandRegistry
.findFirst(statement)
.orElse(defaultCypherCommand)
.accept(session, statement);
} catch (UserInterruptException ignored) {
} catch (EndOfFileException e) {
logger.log("Goodbye!");
return;
}
}
}