org.jline.reader.UserInterruptException Java Examples
The following examples show how to use
org.jline.reader.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: Cli.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 6 votes |
/** * 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(); } } }
Example #2
Source File: SimpleTerminalConsole.java From TerminalConsoleAppender with MIT License | 6 votes |
private void readCommands(Terminal terminal) { LineReader reader = buildReader(LineReaderBuilder.builder().terminal(terminal)); TerminalConsoleAppender.setReader(reader); try { String line; while (isRunning()) { try { line = reader.readLine("> "); } catch (EndOfFileException ignored) { // Continue reading after EOT continue; } if (line == null) { break; } processInput(line); } } catch (UserInterruptException e) { shutdown(); } finally { TerminalConsoleAppender.setReader(null); } }
Example #3
Source File: Console.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Start the interactive console, return error code on exit * * @throws IOException */ public void start() throws IOException { loadSettings(); loadHistory(); consoleIO.writeln(APP_CFG.getFullName()); consoleIO.writeln("Working dir: " + settingMap.get(WorkDir.NAME).getAsString()); consoleIO.writeln("Type 'help' for help."); int exitCode = 0; try { boolean exitFlag = false; while (!exitFlag) { final String command = consoleIO.readCommand(); if (command == null) { // EOF break; } exitFlag = executeCommand(command); if (exitOnError && consoleIO.wasErrorWritten()) { exitCode = 2; exitFlag = true; } } } catch (UserInterruptException | EndOfFileException e) { exitCode = 0; } finally { disconnect.execute(false); } saveSettings(); saveHistory(); if (exitCode != 0) { System.exit(exitCode); } consoleIO.writeln("Bye"); consoleIO.getOutputStream().close(); }
Example #4
Source File: LoginCommand.java From rug-cli with GNU General Public License v3.0 | 6 votes |
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); } }
Example #5
Source File: TerminalProcessor.java From sshd-shell-spring-boot with Apache License 2.0 | 5 votes |
private void processInputs(LineReader reader, IntConsumer exitCallback) { try { processUserInput(reader, exitCallback); } catch (UserInterruptException ex) { // Need not concern with this exception log.warn("[{}] Ctrl-C interrupt", SshSessionContext.<String>get(Constants.USER)); exitCallback.accept(1); } }
Example #6
Source File: Setup.java From jsqsh with Apache License 2.0 | 5 votes |
@Override public int execute(Session session, SqshOptions opts) throws Exception { Options options = (Options)opts; LineReader in = session.getContext().getConsole().getSimpleLineReader(); try { if (options.arguments.size() > 0) { String path = options.arguments.get(0); if (path.equals("connections")) { doConnectionWizard(session, session.out, in); } else if (path.equals("drivers")) { doDriverWizard(session, session.out, in); } else { session.err.println("Unrecognized setup type \"" + path + "\""); } } else { doWelcome(session, session.out, in); } } catch (UserInterruptException e) { session.err.println("Aborting setup"); return 1; } return 0; }
Example #7
Source File: InteractiveMode.java From rdflint with MIT License | 4 votes |
/** * execute interacitve mode. */ void execute(Map<String, String> cmdOptions) throws IOException { // initialize graph model Model m = ModelFactory.createDefaultModel(); // initialize jline Terminal terminal = TerminalBuilder.builder() .system(true) .build(); LineReader lineReader = LineReaderBuilder.builder() .terminal(terminal) .completer(new InteractiveCompleter(m)) .parser(new InteractiveParser()) .build(); String welcome = MessageFormat .format(messages.getString("interactivemode.welcome"), RdfLint.VERSION); System.out.println(welcome);// NOPMD RdfLintParameters params = new RdfLintParameters(); try { // load configurations params = ConfigurationLoader.loadParameters(cmdOptions); // load rdf m.removeAll(); m.add(DatasetLoader.loadRdfSet(params, params.getTargetDir())); } catch (Exception ex) { System.out.println(ex.getLocalizedMessage()); // NOPMD } while (true) { String line; try { line = lineReader.readLine("SPARQL> "); } catch (UserInterruptException | EndOfFileException e) { return; } if (!interactiveCommand(System.out, line, params, cmdOptions, m)) { return; } } }