Skip to content

Commit dff9c8a

Browse files
vladimyragnivade
authored andcommitted
Add cli spinners (#203)
1 parent 84eb2bf commit dff9c8a

File tree

3 files changed

+97
-17
lines changed

3 files changed

+97
-17
lines changed

lib/tldr.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const sample = require('lodash/sample');
44
const fs = require('fs');
55
const ms = require('ms');
6+
const ora = require('ora');
67
const cache = require('./cache');
78
const search = require('./search');
89
const platform = require('./platform');
@@ -86,10 +87,11 @@ exports.clearCache = () => {
8687
};
8788

8889
exports.updateCache = () => {
89-
console.log('Updating...');
90+
const spinner = ora();
91+
spinner.start('Updating');
9092
return cache.update()
9193
.then(() => {
92-
console.log('Done');
94+
spinner.succeed();
9395
})
9496
.catch((err) => {
9597
console.error(err);
@@ -98,10 +100,11 @@ exports.updateCache = () => {
98100
};
99101

100102
exports.updateIndex = () => {
101-
console.log('Creating index...');
103+
const spinner = ora();
104+
spinner.start('Creating index');
102105
search.createIndex()
103106
.then(() => {
104-
console.log('Done');
107+
spinner.succeed();
105108
})
106109
.catch((err) => {
107110
console.error(err);
@@ -130,6 +133,8 @@ function printPages(pages, singleColumn) {
130133
}
131134

132135
function printBestPage(command, options={}) {
136+
const spinner = ora();
137+
133138
// Trying to get the page from cache first
134139
cache.getPage(command)
135140
.then((content) => {
@@ -140,15 +145,16 @@ function printBestPage(command, options={}) {
140145
return exit();
141146
}
142147
// If not found, try to update
143-
console.log('Page not found. Updating cache ..');
148+
spinner.start('Page not found. Updating cache');
144149
return cache.update();
145150
})
146151
.then(() => {
147-
console.log('Creating index...');
152+
spinner.succeed();
153+
spinner.start('Creating index');
148154
return search.createIndex();
149155
})
150156
.then(() => {
151-
console.log('Done');
157+
spinner.succeed();
152158
// And then, try to check in cache again
153159
return cache.getPage(command);
154160
})

package-lock.json

Lines changed: 83 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"marked": "^0.3.9",
5656
"ms": "^2.0.0",
5757
"natural": "^0.5.4",
58+
"ora": "^2.0.0",
5859
"os-homedir": "^1.0.1",
5960
"request": "^2.75.0",
6061
"unzip2": "^0.2.5"

0 commit comments

Comments
 (0)