Java Code Examples for jline.console.ConsoleReader#flush()
The following examples show how to use
jline.console.ConsoleReader#flush() .
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: SparqlPrompt.java From rya with Apache License 2.0 | 6 votes |
@Override public Optional<String> getSparqlWithResults() throws IOException { final ConsoleReader reader = getReader(); reader.setCopyPasteDetection(true); // disable tab completion from activating reader.setHistoryEnabled(false); // don't store SPARQL fragments in the command history try { reader.println("To see more results press [Enter]."); reader.println("Type '" + STOP_COMMAND + "' to stop showing results."); reader.flush(); final String line = reader.readLine("> "); if(line.endsWith(STOP_COMMAND)) { return Optional.of(STOP_COMMAND); } return Optional.absent(); } finally { reader.setHistoryEnabled(true); // restore the ConsoleReader's settings reader.setCopyPasteDetection(false); // restore tab completion } }
Example 2
Source File: JLineCompletionHandler.java From elasticshell with Apache License 2.0 | 6 votes |
/** * Prints out the candidates. If the size of the candidates is greater than the * {@link ConsoleReader#getAutoprintThreshold}, a warning is printed * * @param candidates the list of candidates to print */ protected void printCandidates(final ConsoleReader reader, List<CharSequence> candidates) throws IOException { Set<CharSequence> distinctCandidates = new HashSet<CharSequence>(candidates); if (distinctCandidates.size() > reader.getAutoprintThreshold()) { reader.println(); reader.print(Messages.DISPLAY_CANDIDATES.format(candidates.size())); reader.flush(); char[] allowed = {'y', 'n'}; int c; while ((c = reader.readCharacter(allowed)) != -1) { if (c=='n') { reader.println(); return; } if (c=='y') { break; } reader.beep(); } } reader.println(); reader.printColumns(sortCandidates(distinctCandidates)); }
Example 3
Source File: ConsoleUtil.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static CursorBuffer stashLine(ConsoleReader console) { CursorBuffer stashed = console.getCursorBuffer().copy(); try { console.getOutput().write("\u001b[1G\u001b[K"); console.flush(); } catch (IOException e) { e.printStackTrace(); } return stashed; }
Example 4
Source File: ConsoleUtil.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void printLine(ConsoleReader console, String author, String message) { try { CursorBuffer stashed = stashLine(console); console.println(author + " > " + message); unstashLine(console, stashed); console.flush(); } catch (IOException e) { throw new RuntimeException(e); } }
Example 5
Source File: ConsoleUtil.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static CursorBuffer stashLine(ConsoleReader console) { CursorBuffer stashed = console.getCursorBuffer().copy(); try { console.getOutput().write("\u001b[1G\u001b[K"); console.flush(); } catch (IOException e) { e.printStackTrace(); } return stashed; }
Example 6
Source File: SparqlPrompt.java From rya with Apache License 2.0 | 5 votes |
@Override public Optional<String> getSparql() throws IOException { final ConsoleReader reader = getReader(); reader.setCopyPasteDetection(true); // disable tab completion from activating reader.setHistoryEnabled(false); // don't store SPARQL fragments in the command history try { reader.println("Enter a SPARQL Query."); reader.println("Type '" + EXECUTE_COMMAND + "' to execute the current query."); reader.println("Type '" + CLEAR_COMMAND + "' to clear the current query."); reader.flush(); final StringBuilder sb = new StringBuilder(); String line = reader.readLine("SPARQL> "); while (!line.endsWith(CLEAR_COMMAND) && !line.endsWith(EXECUTE_COMMAND)) { sb.append(line).append("\n"); line = reader.readLine(" -> "); } if (line.endsWith(EXECUTE_COMMAND)) { sb.append(line.substring(0, line.length() - EXECUTE_COMMAND.length())); return Optional.of(sb.toString()); } return Optional.absent(); } finally { reader.setHistoryEnabled(true); // restore the ConsoleReader's settings reader.setCopyPasteDetection(false); // restore tab completion } }
Example 7
Source File: ConsoleUtil.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void printLine(ConsoleReader console, String author, String message) throws IOException { CursorBuffer stashed = stashLine(console); console.println(author + " > " + message); unstashLine(console, stashed); console.flush(); }
Example 8
Source File: Main.java From java-repl with Apache License 2.0 | 4 votes |
public static void printCandidates(final ConsoleReader reader, Collection<CharSequence> candidates) throws IOException { Set<CharSequence> distinct = new HashSet<CharSequence>(candidates); if (distinct.size() > reader.getAutoprintThreshold()) { //noinspection StringConcatenation reader.print(Messages.DISPLAY_CANDIDATES.format(candidates.size())); reader.flush(); int c; String noOpt = Messages.DISPLAY_CANDIDATES_NO.format(); String yesOpt = Messages.DISPLAY_CANDIDATES_YES.format(); char[] allowed = {yesOpt.charAt(0), noOpt.charAt(0)}; while ((c = reader.readCharacter(allowed)) != -1) { String tmp = new String(new char[]{(char) c}); if (noOpt.startsWith(tmp)) { reader.println(); return; } else if (yesOpt.startsWith(tmp)) { break; } else { reader.beep(); } } } // copy the values and make them distinct, without otherwise affecting the ordering. Only do it if the sizes differ. if (distinct.size() != candidates.size()) { Collection<CharSequence> copy = new ArrayList<CharSequence>(); for (CharSequence next : candidates) { if (!copy.contains(next)) { copy.add(next); } } candidates = copy; } reader.println(); reader.printColumns(candidates); }