有没有办法在节点js REPL中启用分页

时间:2015-07-02 05:56:47

标签: node.js less read-eval-print-loop

我希望在节点js REPL中有长输出时看到分页。

这可能,怎么样?

1 个答案:

答案 0 :(得分:1)

Vorpal.js is a Node module that looks like it would do the trick. Vorpal turns your Node app into an interactive CLI, and supports extensions including an implementation of the less command in Node.

Something like this would work:

var vorpal = require('vorpal')();
var less = require('vorpal-less');

vorpal
  .catch('[commands...]')
  .action(function (args, cb) {
    args.commands = args.commands || [];
    var cmd = args.commands.join(' ');
    var res;
    try {
      res = eval(cmd);
    } catch(e) {
      res = e;
    }
    this.log(res);
    cb();
  });

vorpal
  .delimiter('myrepl>')
  .show();

This will turn your application into a REPL within the context of your app, which can also accept the less command:

$ node myrepl.js
myrepl> 6 * 6 | less

36

: (less prompt)

Disclaimer: I wrote Vorpal