Clear terminal window in Node.js readline shell

后端 未结 7 879
长情又很酷
长情又很酷 2021-01-31 05:41

I have a simple readline shell written in Coffeescript:

rl = require \'readline\'
cli = rl.createInterface process.std         


        
7条回答
  •  悲哀的现实
    2021-01-31 06:08

    Vorpal.js makes things like this really easy.

    For an interactive CLI with a clear command as well as a REPL within the context of your application, do this:

    var vorpal = require('vorpal')();
    var repl = require('vorpal-repl');
    
    vorpal
      .delimiter('hello>')
      .use(repl)
      .show();
    
    vorpal
      .command('clear', 'Clears the screen.')
      .action(function (args, cb) {
        var blank = '';
        for (var i = 0; i < process.stdout.rows; ++i) {
          blank += '\n';
        }
        vorpal.ui.rewrite(blank);
        vorpal.ui.rewrite('');
        cb();
      });
    

提交回复
热议问题