-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Chalk from 'chalk'; | ||
class ChalkTest { | ||
test() { | ||
const log = console.log; | ||
|
||
// Combine styled and normal strings | ||
log(Chalk.blue('Hello') + ' World' + Chalk.red('!')); | ||
|
||
// Compose multiple styles using the chainable API | ||
log(Chalk.blue.bgRed.bold('Hello world!')); | ||
|
||
// Pass in multiple arguments | ||
log(Chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz')); | ||
|
||
// Nest styles | ||
log(Chalk.red('Hello', Chalk.underline.bgBlue('world') + '!')); | ||
|
||
// Nest styles of the same type even (color, underline, background) | ||
log( | ||
Chalk.green( | ||
'I am a green line ' + Chalk.blue.underline.bold('with a blue substring') + ' that becomes green again!' | ||
) | ||
); | ||
|
||
// ES2015 template literal | ||
log(` | ||
CPU: ${Chalk.red('90%')} | ||
RAM: ${Chalk.green('40%')} | ||
DISK: ${Chalk.yellow('70%')} | ||
`); | ||
|
||
// // ES2015 tagged template literal | ||
// log(Chalk` | ||
// CPU: {red ${cpu.totalPercent}%} | ||
// RAM: {green ${(ram.used / ram.total) * 100}%} | ||
// DISK: {rgb(255,131,0) ${(disk.used / disk.total) * 100}%} | ||
// `); | ||
|
||
// Use RGB colors in terminal emulators that support it. | ||
log(Chalk.keyword('orange')('Yay for orange colored text!')); | ||
log(Chalk.rgb(123, 45, 67).underline('Underlined reddish color')); | ||
log(Chalk.hex('#DEADED').bold('Bold gray!')); | ||
} | ||
} | ||
|
||
export { ChalkTest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import inquirer from 'inquirer'; | ||
import ProgressBar from 'progress'; | ||
|
||
const FruitChoice = { | ||
type: 'list', | ||
name: 'pickFruit', | ||
message: 'Pick ingredients for your smoothie', | ||
help: '', | ||
choices: [ | ||
{ | ||
name: 'Orange', | ||
value: 'orange', | ||
}, | ||
{ | ||
name: 'Banan', | ||
value: 'banan', | ||
}, | ||
{ | ||
name: 'Apple', | ||
value: 'apple', | ||
}, | ||
{ | ||
name: 'Blackberry', | ||
value: 'blackberry', | ||
}, | ||
{ | ||
name: 'Kale', | ||
value: 'kale', | ||
}, | ||
{ | ||
name: 'Strawberry', | ||
value: 'strawberry', | ||
}, | ||
{ | ||
name: 'Spinach', | ||
value: 'spinach', | ||
}, | ||
], | ||
}; | ||
|
||
const SmoothieBase = { | ||
type: 'list', | ||
name: 'pickBase', | ||
message: 'Now pick your smoothie base', | ||
help: '', | ||
choices: [ | ||
{ | ||
name: 'Yogurt', | ||
value: 'yogurt', | ||
}, | ||
{ | ||
name: 'Milk', | ||
value: 'milk', | ||
}, | ||
], | ||
}; | ||
|
||
let AnswerSet = {}; | ||
|
||
const HandleAnswers = (answers) => { | ||
let questionSet = null; | ||
if (!answers) { | ||
questionSet = FruitChoice; | ||
} else { | ||
AnswerSet = { ...AnswerSet, ...answers }; | ||
if (answers.pickFruit) { | ||
questionSet = SmoothieBase; | ||
} else if (answers.pickBase) { | ||
MakeSmoothie(AnswerSet); | ||
} | ||
} | ||
if (questionSet) { | ||
inquirer | ||
.prompt(questionSet) | ||
.then((answers) => HandleAnswers(answers)) | ||
.catch((error) => { | ||
if (error.isTtyError) { | ||
console.error('isTtyError'); | ||
} | ||
console.error(error); | ||
}); | ||
} | ||
}; | ||
|
||
const MakeSmoothie = (answerSet) => { | ||
console.log(`Making an awesome ${answerSet.pickFruit} ${answerSet.pickBase} smoothie`); | ||
var bar = new ProgressBar(':bar', { total: 80 }); | ||
var timer = setInterval(function () { | ||
bar.tick(); | ||
if (bar.complete) { | ||
console.log('\nSmoothie Done !\n'); | ||
clearInterval(timer); | ||
} | ||
}, 100); | ||
}; | ||
|
||
class InquirerCli { | ||
start(options) { | ||
HandleAnswers(options); | ||
} | ||
} | ||
|
||
export { InquirerCli }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,11 @@ | ||
import Chalk from "chalk"; | ||
const log = console.log; | ||
import { ChalkTest } from './ChalkTest'; | ||
import { InquirerCli } from './cli'; | ||
|
||
// Combine styled and normal strings | ||
log(Chalk.blue('Hello') + ' World' + Chalk.red('!')); | ||
console.log('############## Running Chalk test #############'); | ||
var chalkTest = new ChalkTest(); | ||
chalkTest.test(); | ||
console.log('################ Chalk test Done ##############'); | ||
|
||
// Compose multiple styles using the chainable API | ||
log(Chalk.blue.bgRed.bold('Hello world!')); | ||
|
||
// Pass in multiple arguments | ||
log(Chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz')); | ||
|
||
// Nest styles | ||
log(Chalk.red('Hello', Chalk.underline.bgBlue('world') + '!')); | ||
|
||
// Nest styles of the same type even (color, underline, background) | ||
log( | ||
Chalk.green( | ||
'I am a green line ' + | ||
Chalk.blue.underline.bold('with a blue substring') + | ||
' that becomes green again!' | ||
) | ||
); | ||
|
||
// ES2015 template literal | ||
log(` | ||
CPU: ${Chalk.red('90%')} | ||
RAM: ${Chalk.green('40%')} | ||
DISK: ${Chalk.yellow('70%')} | ||
`); | ||
|
||
// // ES2015 tagged template literal | ||
// log(Chalk` | ||
// CPU: {red ${cpu.totalPercent}%} | ||
// RAM: {green ${(ram.used / ram.total) * 100}%} | ||
// DISK: {rgb(255,131,0) ${(disk.used / disk.total) * 100}%} | ||
// `); | ||
|
||
// Use RGB colors in terminal emulators that support it. | ||
log(Chalk.keyword('orange')('Yay for orange colored text!')); | ||
log(Chalk.rgb(123, 45, 67).underline('Underlined reddish color')); | ||
log(Chalk.hex('#DEADED').bold('Bold gray!')); | ||
console.log('################ CLI Demo Begins ##############'); | ||
var cli = new InquirerCli(); | ||
cli.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters