如何在运行我的控制台应用程序Windows CMD后清除控制台?

时间:2017-04-12 20:51:15

标签: javascript console-application

我创建了这个简单的控制台应用程序来使用来自API的数据,我正在寻找一种方法,在程序运行的任何时候,用户控制台上的先前内容都将被清除。我认为clear()应该这样做,但它似乎并没有起作用。有关如何执行此操作的任何帮助



'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();




1 个答案:

答案 0 :(得分:0)

使用cli-clear包而不是clear终于工作了