jline.console.history.History类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中jline.console.history.History类的一些代码示例,展示了History类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。History类的具体详情如下:
包路径:jline.console.history.History
类名称:History

History介绍

[英]Console history.
[中]控制台历史记录。

代码示例

代码示例来源:origin: prestodb/presto

String partial = squeezeStatement(buffer.toString());
if (!partial.isEmpty()) {
  reader.getHistory().add(partial);
  int historyIndex = parseInt(command.substring(1));
  History history = reader.getHistory();
  if ((historyIndex <= 0) || (historyIndex > history.index())) {
    System.err.println("Command does not exist");
    continue;
  line = history.get(historyIndex - 1).toString();
  System.out.println(commandPrompt + line);
reader.getHistory().add(squeezeStatement(split.statement()) + split.terminator());

代码示例来源:origin: apache/hive

public boolean history(String line) {
 Iterator hist = beeLine.getConsoleReader().getHistory().entries();
 String[] tmp;
 while(hist.hasNext()){
  tmp = hist.next().toString().split(":", 2);
  tmp[0] = Integer.toString(Integer.parseInt(tmp[0]) + 1);
  beeLine.output(beeLine.getColorBuffer().pad(tmp[0], 6)
    .append(":" + tmp[1]));
 }
 return true;
}

代码示例来源:origin: jline/jline

switch (c) {
  case '!':
    if (history.size() == 0) {
      throw new IllegalArgumentException("!!: event not found");
    rep = history.get(history.index() - 1).toString();
    break;
  case '#':
      throw new IllegalArgumentException("!?" + sc + ": event not found");
    } else {
      rep = history.get(idx).toString();
    if (history.size() == 0) {
      throw new IllegalArgumentException("!$: event not found");
    String previous = history.get(history.index() - 1).toString().trim();
    int lastSpace = previous.lastIndexOf(' ');
    if(lastSpace != -1) {
      if (idx > 0 && idx <= history.size()) {
        rep = (history.get(history.index() - idx)).toString();
      } else {
        throw new IllegalArgumentException((neg ? "!-" : "!") + str.substring(i1, i) + ": event not found");
      if (idx > history.index() - history.size() && idx <= history.index()) {
        rep = (history.get(idx - 1)).toString();
      } else {
        throw new IllegalArgumentException((neg ? "!-" : "!") + str.substring(i1, i) + ": event not found");

代码示例来源:origin: jline/jline

public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
  if (startIndex >= history.size()) {
    startIndex = history.size() - 1;
  }
  ListIterator<History.Entry> it = history.entries(startIndex);
  if (searchIndex != -1 && it.hasNext()) {
    it.next();
  }
  while (it.hasNext()) {
    History.Entry e = it.next();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

代码示例来源:origin: apache/accumulo

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
  throws IOException {
 if (cl.hasOption(clearHist.getOpt())) {
  shellState.getReader().getHistory().clear();
 } else {
  Iterator<Entry> source = shellState.getReader().getHistory().entries();
  Iterator<String> historyIterator = Iterators.transform(source,
    input -> String.format("%d: %s", input.index() + 1, input.value()));
  shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
 }
 return 0;
}

代码示例来源:origin: com.netflix.eureka2/eureka-testkit

private void loadHistory() {
  if (HISTORY_FILE != null && HISTORY_FILE.exists()) {
    try {
      try (LineNumberReader reader = new LineNumberReader(new FileReader(HISTORY_FILE))) {
        History history = consoleReader.getHistory();
        String line;
        while ((line = reader.readLine()) != null) {
          history.add(line);
        }
      }
    } catch (IOException ignored) {
      System.err.println("ERROR: could not load history file from ~/.eureka_history");
    }
  }
}

代码示例来源:origin: jline/jline

/**
 * Possible states in which the current readline operation may be in.
 */
private static enum State {
  /**
   * The user is just typing away
   */
  NORMAL,
  /**
   * In the middle of a emacs seach
   */
  SEARCH,
  FORWARD_SEARCH,
  /**
   * VI "yank-to" operation ("y" during move mode)
   */
  VI_YANK_TO,
  /**
   * VI "delete-to" operation ("d" during move mode)
   */
  VI_DELETE_TO,
  /**
   * VI "change-to" operation ("c" during move mode)
   */
  VI_CHANGE_TO
}

代码示例来源:origin: jline/jline

history.add(historyLine);
history.moveToEnd();

代码示例来源:origin: com.netflix.eureka/eureka2-testkit

@Override
  protected boolean executeCommand(Context context, String[] args) {
    for (int i = 0; i < consoleReader.getHistory().size(); i++) {
      System.out.println(String.format("%4d %s", i + 1, consoleReader.getHistory().get(i)));
    }
    return true;
  }
}

代码示例来源:origin: jline/jline

/**
 * Search backwards in history from the current position.
 *
 * @param searchTerm substring to search for.
 * @return index where the substring has been found, or -1 else.
 */
public int searchBackwards(String searchTerm) {
  return searchBackwards(searchTerm, history.index());
}

代码示例来源:origin: future-architect/uroborosql

int sizeLen = String.valueOf(console.getHistory().size()).length();
console.getHistory().forEach(entry -> {
  try {
    String value = entry.value().toString();

代码示例来源:origin: dariober/ASCIIGenome

@Test
public void canReadHistory() throws IOException {
  ASCIIGenomeHistory ag= new ASCIIGenomeHistory("test_data/asciigenome.yaml");
  assertEquals(8, ag.getFiles().size());
  assertEquals(4, ag.getPositions().size());
  assertEquals(6, ag.getCommandHistory().size());
  assertEquals(1, ag.getReference().size());
  
  ag= new ASCIIGenomeHistory("non-existing.yaml");
  assertEquals(0, ag.getFiles().size());
  ag= new ASCIIGenomeHistory();
  assertNotNull(ag.getFileName());
}

代码示例来源:origin: oldmanpushcart/greys-anatomy

public GreysConsole(InetSocketAddress address) throws IOException {
  this.console = initConsoleReader();
  this.history = initHistory();
  this.out = console.getOutput();
  this.history.moveToEnd();
  this.console.setHistoryEnabled(true);
  this.console.setHistory(history);
  this.console.setExpandEvents(false);
  this.socket = connect(address);
  // 关闭会话静默
  disableSilentOfSession();
  // 初始化自动补全
  initCompleter();
  this.isRunning = true;
  activeConsoleReader();
  socketWriter.write("version\n");
  socketWriter.flush();
  loopForWriter();
}

代码示例来源:origin: com.netflix.eureka/eureka2-testkit

private void loadHistory() {
  if (HISTORY_FILE != null && HISTORY_FILE.exists()) {
    try {
      try (LineNumberReader reader = new LineNumberReader(new FileReader(HISTORY_FILE))) {
        History history = consoleReader.getHistory();
        String line;
        while ((line = reader.readLine()) != null) {
          history.add(line);
        }
      }
    } catch (IOException ignored) {
      System.err.println("ERROR: could not load history file from ~/.eureka_history");
    }
  }
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

/**
 * Possible states in which the current readline operation may be in.
 */
private static enum State {
  /**
   * The user is just typing away
   */
  NORMAL,
  /**
   * In the middle of a emacs seach
   */
  SEARCH,
  FORWARD_SEARCH,
  /**
   * VI "yank-to" operation ("y" during move mode)
   */
  VI_YANK_TO,
  /**
   * VI "delete-to" operation ("d" during move mode)
   */
  VI_DELETE_TO,
  /**
   * VI "change-to" operation ("c" during move mode)
   */
  VI_CHANGE_TO
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

history.add(historyLine);
history.moveToEnd();

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
  if (startIndex >= history.size()) {
    startIndex = history.size() - 1;
  }
  ListIterator<History.Entry> it = history.entries(startIndex);
  if (searchIndex != -1 && it.hasNext()) {
    it.next();
  }
  while (it.hasNext()) {
    History.Entry e = it.next();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

代码示例来源:origin: com.netflix.eureka2/eureka-testkit

@Override
  protected boolean executeCommand(Context context, String[] args) {
    for (int i = 0; i < consoleReader.getHistory().size(); i++) {
      System.out.println(String.format("%4d %s", i + 1, consoleReader.getHistory().get(i)));
    }
    return true;
  }
}

代码示例来源:origin: org.apache.accumulo/accumulo-shell

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
  throws IOException {
 if (cl.hasOption(clearHist.getOpt())) {
  shellState.getReader().getHistory().clear();
 } else {
  Iterator<Entry> source = shellState.getReader().getHistory().entries();
  Iterator<String> historyIterator = Iterators.transform(source, new Function<Entry,String>() {
   @Override
   public String apply(Entry input) {
    return String.format("%d: %s", input.index() + 1, input.value());
   }
  });
  shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
 }
 return 0;
}

代码示例来源:origin: jline/jline

/**
 * Search forwards in history from the current position.
 *
 * @param searchTerm substring to search for.
 * @return index where the substring has been found, or -1 else.
 */
public int searchForwards(String searchTerm) {
  return searchForwards(searchTerm, history.index());
}

相关文章