@Override public Iterable<? extends History.Entry> getHistory() { return lineReader.getHistory(); }
public void close() { if (closed.compareAndSet(false, true)) { if (running) { try { reader.getHistory().save(); } catch (IOException e) { // ignore } } running = false; if (thread != Thread.currentThread() && thread != null) { thread.interrupt(); } if (closeCallback != null) { closeCallback.run(); } if (terminal instanceof AutoCloseable) { try { ((AutoCloseable) terminal).close(); } catch (Exception e) { // Ignore } } if (session != null) session.close(); } }
public void close() { if (closed.compareAndSet(false, true)) { if (running) { try { reader.getHistory().save(); } catch (IOException e) { // ignore } } running = false; if (thread != Thread.currentThread() && thread != null) { thread.interrupt(); } if (closeCallback != null) { closeCallback.run(); } if (terminal instanceof AutoCloseable) { try { ((AutoCloseable) terminal).close(); } catch (Exception e) { // Ignore } } if (session != null) session.close(); } }
private String calculateCommand(int currentOffset, Set<Integer> offsets) { if (!offsets.add(currentOffset)) { throw new IllegalArgumentException( "Cycled rerun of commands from history " + offsets); } History history = sqlLine.getLineReader().getHistory(); Iterator<History.Entry> iterator = currentOffset > 0 ? history.iterator(currentOffset - 1) : history.reverseIterator(history.size() - 1 + currentOffset); String command = iterator.next().line(); if (command.trim().startsWith("!/") || command.startsWith("!rerun")) { String[] cmd = sqlLine.split(command); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) { return command; } int offset = cmd.length == 1 ? -1 : Integer.parseInt(cmd[1]); if (history.size() < offset || history.size() - 1 < -offset) { return command; } return calculateCommand(offset, offsets); } return command; }
private String calculateCommand(int currentOffset, Set<Integer> offsets) { if (!offsets.add(currentOffset)) { throw new IllegalArgumentException( "Cycled rerun of commands from history " + offsets); } History history = sqlLine.getLineReader().getHistory(); Iterator<History.Entry> iterator = currentOffset > 0 ? history.iterator(currentOffset - 1) : history.reverseIterator(history.size() - 1 + currentOffset); String command = iterator.next().line(); if (command.trim().startsWith("!/") || command.startsWith("!rerun")) { String[] cmd = sqlLine.split(command); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) { return command; } int offset = cmd.length == 1 ? -1 : Integer.parseInt(cmd[1]); if (history.size() < offset || history.size() - 1 < -offset) { return command; } return calculateCommand(offset, offsets); } return command; }
private void setLineReaderHistoryIntVariable( String variableName, String value, SqlLineProperty property) { LineReader lineReader = sqlLine.getLineReader(); if (lineReader == null) { return; } int currentValue = getInt(property); try { if (DEFAULT.equals(value)) { if (currentValue == (Integer) property.defaultValue()) { return; } else { lineReader.setVariable(variableName, property.defaultValue()); lineReader.getHistory().save(); propertiesMap.put(property, property.defaultValue()); return; } } int parsedValue = Integer.parseInt(value); if (parsedValue == currentValue) { return; } else { lineReader.setVariable(variableName, parsedValue); lineReader.getHistory().save(); propertiesMap.put(property, parsedValue); } } catch (Exception e) { sqlLine.handleException(e); } }
private void setLineReaderHistoryIntVariable( String variableName, String value, SqlLineProperty property) { LineReader lineReader = sqlLine.getLineReader(); if (lineReader == null) { return; } int currentValue = getInt(property); try { if (DEFAULT.equals(value)) { if (currentValue == (Integer) property.defaultValue()) { return; } else { lineReader.setVariable(variableName, property.defaultValue()); lineReader.getHistory().save(); propertiesMap.put(property, property.defaultValue()); return; } } int parsedValue = Integer.parseInt(value); if (parsedValue == currentValue) { return; } else { lineReader.setVariable(variableName, parsedValue); lineReader.getHistory().save(); propertiesMap.put(property, parsedValue); } } catch (Exception e) { sqlLine.handleException(e); } }
private void runInteractive() { SignalHandler handler = signal -> _logger.debugf("Client: Ignoring signal: %s\n", signal); Signal.handle(new Signal("INT"), handler); try { while (!_exit) { try { String rawLine = _reader.readLine("batfish> "); if (rawLine == null) { break; } processCommand(rawLine); } catch (UserInterruptException e) { continue; } } } catch (EndOfFileException e) { // ignored } catch (Throwable t) { t.printStackTrace(); } finally { try { _reader.getHistory().save(); } catch (IOException e) { e.printStackTrace(); } } }
public void setHistoryFile(String historyFile) { final String currentValue = get(HISTORY_FILE); if (Objects.equals(currentValue, historyFile) || Objects.equals(currentValue, Commands.expand(historyFile))) { return; } if (DEFAULT.equalsIgnoreCase(historyFile)) { set(HISTORY_FILE, DEFAULT); } else { propertiesMap.put(HISTORY_FILE, Commands.expand(historyFile)); } if (sqlLine != null && sqlLine.getLineReader() != null) { History history = sqlLine.getLineReader().getHistory(); if (history == null) { history = new DefaultHistory(); } else { try { history.save(); } catch (IOException e) { sqlLine.handleException(e); } } sqlLine.getLineReader() .setVariable(LineReader.HISTORY_FILE, get(HISTORY_FILE)); history.attach(sqlLine.getLineReader()); } }
public void setHistoryFile(String historyFile) { final String currentValue = get(HISTORY_FILE); if (Objects.equals(currentValue, historyFile) || Objects.equals(currentValue, Commands.expand(historyFile))) { return; } if (DEFAULT.equalsIgnoreCase(historyFile)) { set(HISTORY_FILE, DEFAULT); } else { propertiesMap.put(HISTORY_FILE, Commands.expand(historyFile)); } if (sqlLine != null && sqlLine.getLineReader() != null) { final History history = sqlLine.getLineReader().getHistory(); if (history != null) { try { history.save(); } catch (IOException e) { sqlLine.handleException(e); } } sqlLine.getLineReader() .setVariable(LineReader.HISTORY_FILE, get(HISTORY_FILE)); new DefaultHistory().attach(sqlLine.getLineReader()); } }
public void rerun(String line, DispatchCallback callback) { String[] cmd = sqlLine.split(line); History history = sqlLine.getLineReader().getHistory(); int size = history.size(); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) {
public void rerun(String line, DispatchCallback callback) { String[] cmd = sqlLine.split(line); History history = sqlLine.getLineReader().getHistory(); int size = history.size(); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) {
History history = reader.getHistory(); if (opt.isSet("clear")) { history.purge();
History history = reader.getHistory(); if (opt.isSet("clear")) { history.purge();
reader.getHistory().save(); } catch (IOException e1) {
reader.setVariable(LineReader.HISTORY_FILE_SIZE, Integer.parseInt(maxFileSizeStr)); history = new HistoryWrapper(reader.getHistory()); session.put(".jline.reader", reader); session.put(".jline.terminal", reader.getTerminal()); session.put(".jline.history", reader.getHistory()); session.put(Session.SCOPE, "shell:bundle:*"); session.put(Session.SUBSHELL, "");
reader.setVariable(LineReader.HISTORY_FILE_SIZE, Integer.parseInt(maxFileSizeStr)); history = new HistoryWrapper(reader.getHistory()); session.put(".jline.reader", reader); session.put(".jline.terminal", reader.getTerminal()); session.put(".jline.history", reader.getHistory()); session.put(Session.SCOPE, "shell:bundle:*"); session.put(Session.SUBSHELL, "");