use of org.jline.reader.LineReader in project felix by apache.
the class Builtin method __files.
public List<Candidate> __files(CommandSession session) {
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
new FilesCompleter(session.currentDir()) {
@Override
protected String getDisplay(Terminal terminal, Path p) {
return getFileDisplay(session, p);
}
}.complete(reader, line, candidates);
return candidates;
}
use of org.jline.reader.LineReader in project felix by apache.
the class Builtin method __directories.
public List<Candidate> __directories(CommandSession session) {
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
new DirectoriesCompleter(session.currentDir()) {
@Override
protected String getDisplay(Terminal terminal, Path p) {
return getFileDisplay(session, p);
}
}.complete(reader, line, candidates);
return candidates;
}
use of org.jline.reader.LineReader in project nifi by apache.
the class CLIMain method runInteractiveCLI.
/**
* Runs the interactive CLI.
*
* @throws IOException if an error occurs
*/
private static void runInteractiveCLI() throws IOException {
// Logger.getLogger("org.jline").setLevel(Level.FINE);
try (final Terminal terminal = TerminalBuilder.builder().name(SHELL_NAME).system(true).nativeSignals(true).signalHandler(Terminal.SignalHandler.SIG_IGN).build();
final PrintStream output = new PrintStream(terminal.output(), true)) {
printHeader(BANNER_FILE, output);
final Context context = createContext(output, true);
final Map<String, Command> topLevelCommands = CommandFactory.createTopLevelCommands(context);
final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
final CommandProcessor commandProcessor = new CommandProcessor(topLevelCommands, commandGroups, context);
final Completer completer = new CLICompleter(topLevelCommands.values(), commandGroups.values());
final LineReader reader = LineReaderBuilder.builder().appName(SHELL_NAME).terminal(terminal).completer(completer).build();
reader.setOpt(LineReader.Option.AUTO_FRESH_LINE);
reader.unsetOpt(LineReader.Option.INSERT_TAB);
while (true) {
try {
final String line = reader.readLine(PROMPT);
if (StringUtils.isBlank(line)) {
continue;
}
final ParsedLine parsedLine = reader.getParsedLine();
final String[] parsedArgs = parsedLine.words().toArray(new String[parsedLine.words().size()]);
commandProcessor.process(parsedArgs);
} catch (UserInterruptException e) {
// Ignore
} catch (EndOfFileException e) {
return;
}
}
}
}
use of org.jline.reader.LineReader in project herddb by diennea.
the class HerdDBCLI method runSqlConsole.
private static void runSqlConsole(Connection connection, Statement statement, boolean pretty) throws IOException {
Terminal terminal = TerminalBuilder.builder().system(true).build();
LineReader reader = LineReaderBuilder.builder().history(new DefaultHistory()).terminal(terminal).build();
String prompt = "herd: ";
while (true) {
String line = null;
try {
line = reader.readLine(prompt);
if (line == null) {
return;
}
executeStatement(true, true, false, false, line, statement, null, false, pretty);
} catch (UserInterruptException | EndOfFileException e) {
return;
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.jline.reader.LineReader in project flink by apache.
the class CliClientTest method verifySqlCompletion.
private void verifySqlCompletion(String statement, int position, List<String> expectedHints) throws IOException {
final MockExecutor mockExecutor = new MockExecutor();
String sessionId = mockExecutor.openSession("test-session");
final SqlCompleter completer = new SqlCompleter(sessionId, mockExecutor);
final SqlMultiLineParser parser = new SqlMultiLineParser(new SqlCommandParserImpl(mockExecutor, sessionId));
try (Terminal terminal = TerminalUtils.createDumbTerminal()) {
final LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();
final ParsedLine parsedLine = parser.parse(statement, position, Parser.ParseContext.COMPLETE);
final List<Candidate> candidates = new ArrayList<>();
final List<String> results = new ArrayList<>();
completer.complete(reader, parsedLine, candidates);
candidates.forEach(item -> results.add(item.value()));
assertThat(results.containsAll(expectedHints)).isTrue();
assertThat(statement).isEqualTo(mockExecutor.receivedStatement);
assertThat(position).isEqualTo(mockExecutor.receivedPosition);
}
}
Aggregations