Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give some samples to encourage developers using it. #1

Open
richardo2016 opened this issue Aug 21, 2019 · 0 comments
Open

Give some samples to encourage developers using it. #1

richardo2016 opened this issue Aug 21, 2019 · 0 comments
Labels

Comments

@richardo2016
Copy link
Collaborator

const chalk = require('@fibjs/chalk');

const os = require('os');

// sample 1
(() => {
    const miles = 18;
    const calculateFeet = miles => miles * 5280;

console.log(chalk`
There are {bold 5280 feet} in a mile.
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
`);
})();

// sample 2
(() => {
    const ram = {
        total: os.totalmem(),
        free: os.freemem(),
        get used () {
            return this.total - this.free
        }
    }
    
// ES2015 template literal
console.log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);

// ES2015 tagged template literal
console.log(chalk`
RAM: {green ${ram.used / ram.total * 100}%}
`);

    // Use RGB colors in terminal emulators that support it.
    console.log(chalk.keyword('orange')('Yay for orange colored text!'));
    console.log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
    console.log(chalk.hex('#DEADED').bold('Bold gray!'));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant