@Override public Iterable<? extends History.Entry> getHistory() { return lineReader.getHistory(); }
@Override public ParsedLine parse(final String line, final int cursor, final ParseContext context) { final ParsedLine parsed = delegate.parse(line, cursor, context); if (context != ParseContext.ACCEPT_LINE) { return parsed; } final String bare = CommentStripper.strip(parsed.line()); if (bare.isEmpty()) { return parsed; } if (cliCmdPredicate.test(bare)) { return parsed; } if (!bare.endsWith(TERMINATION_CHAR)) { throw new EOFError(-1, -1, "Missing termination char", "termination char"); } return parsed; } }
private Candidate createCandidate(String hint) { return new Candidate(AttributedString.stripAnsi(hint), hint, null, null, null, null, true); }
@Override public String readLine() { final String line = lineReader.readLine(prompt); addToHistory(line); return line; }
@Override public ParsedLine parse(String line, int cursor, ParseContext context) { if (!line.trim().endsWith(EOF_CHARACTER) && context != ParseContext.COMPLETE) { throw new EOFError( -1, -1, "New line without EOF character.", NEW_LINE_PROMPT); } final ArgumentList parsedLine = (ArgumentList) super.parse(line, cursor, context); return new SqlArgumentList( parsedLine.line(), parsedLine.words(), parsedLine.wordIndex(), parsedLine.wordCursor(), parsedLine.cursor(), null, parsedLine.rawWordCursor(), parsedLine.rawWordLength()); }
@Override public ParsedLine parse(final String line, final int cursor, final ParseContext context) { final String trimmed = line.trim(); final int adjCursor = adjustCursor(line, trimmed, cursor); return delegate.parse(trimmed, adjCursor, context); }
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { String statement = line.line(); // remove ';' at the end if (statement.endsWith(";")) { statement = statement.substring(0, statement.length() - 1); } // handle SQL client specific commands final String statementNormalized = statement.toUpperCase().trim(); for (String commandHint : COMMAND_HINTS) { if (commandHint.startsWith(statementNormalized) && line.cursor() < commandHint.length()) { candidates.add(createCandidate(commandHint)); } } // fallback to Table API hinting try { executor.completeStatement(context, statement, line.cursor()) .forEach(hint -> candidates.add(createCandidate(hint))); } catch (SqlExecutionException e) { LOG.debug("Could not complete statement at " + line.cursor() + ":" + statement, e); } }
public void setReader(LineReader reader){ this.reader = (LineReaderImpl)reader; out = reader.getTerminal().writer(); }
private static List<String> getHistory(final JLineReader reader) { final List<String> commands = new ArrayList<>(); reader.getHistory().forEach(entry -> commands.add(entry.line())); return commands; }
@Override public void execute(final List<String> args, final PrintWriter terminal) { CliCmdUtil.ensureArgCountBounds(args, 0, 0, HELP); throw new EndOfFileException(); } }
@Test public void shouldCallDelegateWithCorrectParams() { // Given: EasyMock.expect(parsedLine.line()).andReturn(TERMINATED_LINE).anyTimes(); EasyMock.expect(delegate.parse("some-string", 55, ParseContext.ACCEPT_LINE)) .andReturn(parsedLine); EasyMock.replay(delegate, parsedLine); // When: parser.parse("some-string", 55, ParseContext.ACCEPT_LINE); // Then: EasyMock.verify(delegate); }
private void addCandidates(final Collection<String> values, final List<Candidate> candidates) { for (final String value : values) { candidates.add(new Candidate(AttributedString.stripAnsi(value), value, null, null, null, null, true)); } } }
@Test public void shouldPassThroughAnyLineThatDoesNotNeedTrimming() { expect(delegate.parse("line without spaces at ends", 4, ACCEPT_LINE)) .andReturn(parsedLine); replay(delegate); final ParsedLine line = parser.parse("line without spaces at ends", 4, ACCEPT_LINE); assertThat(line, is(parsedLine)); } }