如何将ProcessBar修复到Nodejs CLI的首行?
terminal是: 但实际上这是我真正想要的:进度条总是会成为第一行,然后得到回应,然后在下面显示。
无论如何解决这个问题?
的NodeJS:
var request = require('request'); var ProgressBar = require('progress'); var year=[14,15,16]; var month=[1,2,3,4,5,6,7]; var bar = new ProgressBar('Processing [:bar] :percent', { complete: '=', incomplete: '-', width: 30, total: year.length*month.length, }); /*-------------------------------------*/ function init(year,month){ check(year,month); } function check(year,month){ var options = { method: 'POST', url: 'http://dev.site/date.php', formData:{year:year,month:month} }; request(options, function (error, response, body) { if (error) { console.log(error);; } if (body=='A task @') { bar.tick(); console.log('\n'+body+year+':'+month); }else{ bar.tick(); } }) } /*-------------------------------------*/ for (var i = 0; i < year.length; i++) { for (var n = 0; n < month.length; n++) { init(year[i],month[n]); } }
使用ansi-escapes
你可以做到这一点。
这是一个独立的版本:
const ProgressBar = require('progress'); const ansiEscapes = require('ansi-escapes'); const write = process.stdout.write.bind(process.stdout); let bar = new ProgressBar('Processing [:bar] :percent', { complete : '=', incomplete : '-', width : 30, total : 100 }); // Start by clearing the screen and positioning the cursor on the second line // (because the progress bar will be positioned on the first line) write(ansiEscapes.clearScreen + ansiEscapes.cursorTo(0, 1)); let i = 0; setInterval(() => { // Save cursor position and move it to the top left corner. write(ansiEscapes.cursorSavePosition + ansiEscapes.cursorTo(0, 0)); // Update the progress bar. bar.tick(); // Restore the cursor position. write(ansiEscapes.cursorRestorePosition); // Write a message every 10 ticks. if (++i % 10 === 0) { console.log('Now at', i); } // We're done. if (i === 100) { process.exit(0); } }, 100);
- 优雅的方法来过滤标准输出内容文件? 或者关掉摩卡的微调?
- 编译NodeJS命令行应用程序
- 显示最近发布的npm软件包版本,包括beta版本
- 运行命令后npm install -g @angular \ cli我收到一个npm ERR! 代码ENOLOCAL
- 有没有办法在node.js cli应用程序中具有可展开/可折叠的json?
- JavaScript – 使用JasminetestingNodeJS readline.createInterface的实现
- 节点包 – 是否有可能在package.json中插入一个variables?
- Node.js:需要帮助来创build命令行界面
- testingnode.js中的实际输出是否为terminal