Example #1
0
 private void prompt() {
   if (prompt == null) {
     prompt(
         lineStore.isLastLineNo(bottomLineNo)
             ? "(END)"
             : (topLineNo + ", " + bottomLineNo + ": "));
   } else {
     prompt(prompt);
     prompt = null;
   }
 }
Example #2
0
  /**
   * Do the paging, reading commands from our private console input pipe to figure out what to do
   * next.
   *
   * @param r the source of data to be paged.
   * @throws IOException
   */
  private void pager() throws IOException {
    // Output first page.
    console.clear();
    bottomLineNo = -1;
    boolean exit = false;
    nextPage();

    // Process commands until we reach the EOF on the data source or
    // the command pipe.
    while (!exit) {
      prompt();
      int ch = pr.read();
      erasePrompt();
      switch (ch) {
        case -1:
          exit = true;
          break;
        case ' ':
        case 'f':
          if (lineStore.isLastLineNo(bottomLineNo)) {
            exit = true;
          } else {
            nextPage();
          }
          break;
        case 'b':
          prevPage();
          break;
        case 'k':
        case 'y':
          prevLine();
          break;
        case '\n':
          if (lineStore.isLastLineNo(bottomLineNo)) {
            exit = true;
          } else {
            nextLine();
          }
          break;
        case 'u':
          prevScreenLine();
          break;
        case 'd':
          nextScreenLine();
          break;
        case '<':
          gotoPage(0);
          break;
        case '>':
          gotoLastPage();
          break;
        case '/':
          searchForwards();
          break;
        case '?':
          searchBackwards();
          break;
        case '\004': // ^D
        case 'q':
          exit = true;
          break;
        case 'h':
          help();
        default:
          // ignore
      }
    }
  }