0
我創建了這個簡單的控制檯應用程序來使用API中的數據,我正在尋找一種方法,在用戶控制檯上的以前的內容將在程序運行時被清除。我認爲clear()
應該這樣做,但它似乎並沒有工作。如何做到這一點運行我的控制檯應用程序Windows CMD後,如何清除控制檯?
'use strict';
var request = require('request'),
clear = require('clear'),
figlet = require('figlet'),
inquirer = require('inquirer'),
chalk = require('chalk'),
Spinner = require('clui').Spinner;
clear();
console.log(
chalk.cyan(
figlet.textSync('Welcome!', { horizontalLayout: 'left' })
)
);
function getIpadd() {
var status = new Spinner('Getting your IP, please wait...');
status.start();
//Request the IP address
request('https://api.ipify.org?format=json', function (err, res, data){
if (err) {
console.log(err)
return;
}
data = JSON.parse(data);
status.stop();
console.log('\nYour IP is: ' + data.ip + '\n');
exitApp();
});
}
function startApp() {
inquirer.prompt([ {
type: 'list',
name: 'option',
message: 'Press enter to Check Ip address',
choices: [
'Check my Ip address',
]
} ]).then(function (answer) {
if(answer.option === 'Check my Ip address'){
getIpadd();
};
});
}
//Function that Exits the app
function exitApp() {
inquirer.prompt([ {
type: 'list',
name: 'option',
message: 'Exit?',
choices: [
'Yes',
'No',
]
} ]).then(function (answer) {
if(answer.option === 'No') return startApp();
if(answer.option === 'Yes') return console.log(chalk.yellow('=============Thanks for using this app!============='));
});
}
startApp();
http://stackoverflow.com/questions/3011600/clear-javascript-console- in-google-chrome也許其中一個答案可以幫助你 –
命令行使用'cls'清除。您可以嘗試使用'gulp-shell'或'gulp-exec'運行它。不提交作爲答案,因爲我不知道這是否會按我的預期工作。 – Amy
這將工作在大多數終端不能確定在Windows'console.log(「\ 033 [2J」)' – adrianj98