Skip to content

Commit

Permalink
animated output - fixes sindresorhus#1
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 16, 2015
1 parent c053d44 commit 2073d94
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
59 changes: 49 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,65 @@
'use strict';
var meow = require('meow');
var speedtest = require('speedtest-net');
var updateNotifier = require('update-notifier');
var roundTo = require('round-to');
var chalk = require('chalk');
var logUpdate = require('log-update');
var elegantSpinner = require('elegant-spinner');

meow({
var cli = meow({
help: [
'Usage',
' $ speed-test'
]
});

speedtest.visual({maxTime: 20000}, function (err, res) {
if (err) {
console.error(err);
process.exit(1);
}
updateNotifier({pkg: cli.pkg}).notify();

console.log([
var stats = {
ping: '',
download: '',
upload: ''
};

var state = 'ping';
var frame = elegantSpinner();

function getSpinner(x) {
return state === x ? chalk.cyan.dim(frame()) : '';
}

function render() {
logUpdate([
'',
' Ping: ' + chalk.cyan(res.server.ping + chalk.dim(' ms')),
' Download: ' + chalk.cyan(roundTo(res.speeds.download, 1) + chalk.dim(' Mbps')),
' Upload: ' + chalk.cyan(roundTo(res.speeds.upload, 1) + chalk.dim(' Mbps'))
' Ping ' + stats.ping + getSpinner('ping'),
' Download ' + stats.download + getSpinner('download'),
' Upload ' + stats.upload + getSpinner('upload')
].join('\n'));
}

var st = speedtest({maxTime: 20000});

setInterval(render, 50);

st.once('testserver', function (server) {
state = 'download';
stats.ping = chalk.cyan(Math.round(server.bestPing) + chalk.dim(' ms'));
});

st.once('downloadspeed', function (speed) {
state = 'upload';
stats.download = chalk.cyan(roundTo(speed, 1) + chalk.dim(' Mbps'));
});

st.once('uploadspeed', function (speed) {
state = '';
stats.upload = chalk.cyan(roundTo(speed, 1) + chalk.dim(' Mbps'));
render();
process.exit();
});

st.on('error', function (err) {
console.error(err);
process.exit(1);
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
],
"dependencies": {
"chalk": "^1.1.0",
"elegant-spinner": "^1.0.0",
"log-update": "^1.0.0",
"meow": "^3.3.0",
"round-to": "^1.0.0",
"speedtest-net": "^1.0.3"
"speedtest-net": "^1.0.3",
"update-notifier": "^0.5.0"
},
"devDependencies": {
"ava": "0.0.4",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Test your internet connection speed and ping using [speedtest.net](http://www.speedtest.net) from the CLI
![](screenshot.png)
![](screenshot.gif)


## Install
Expand Down
Binary file added screenshot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshot.png
Binary file not shown.

0 comments on commit 2073d94

Please sign in to comment.