Skip to content

Give some samples to encourage developers using it. #1

Description

@richardo2016
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!'));
})();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions