diff --git a/examples/gradient.js b/examples/gradient.js new file mode 100644 index 0000000..1856464 --- /dev/null +++ b/examples/gradient.js @@ -0,0 +1,39 @@ +import chalk from '../source/index.js'; + +// Set color level to enable gradients (adjust based on terminal support) +chalk.level = 3; + +// Demonstrate gradient feature +console.log(chalk.bold('Chalk Gradient Examples')); +console.log(); + +// Simple two-color gradient +console.log('Two-color gradient:'); +console.log(chalk.gradient('#ff0000', '#0000ff')('Hello World')); +console.log(); + +// RGB array gradient +console.log('RGB array gradient:'); +console.log(chalk.gradient([255, 0, 0], [0, 255, 0], [0, 0, 255])('Rainbow Text')); +console.log(); + +// Multi-color gradient +console.log('Multi-color gradient:'); +console.log(chalk.gradient('#ff0000', '#ffff00', '#00ff00', '#00ffff', '#0000ff')('Color Spectrum')); +console.log(); + +// Combining with other styles +console.log('Gradient with bold:'); +console.log(chalk.gradient('#ff0080', '#8000ff').bold('Bold Gradient')); +console.log(); + +// Gradient on themed chalk +const themedChalk = chalk.theme({ + rainbow: chalk.gradient('#ff0000', '#ffff00', '#00ff00', '#00ffff', '#0000ff'), +}); + +console.log('Themed gradient:'); +console.log(themedChalk.rainbow('Themed Rainbow Text')); +console.log(); + +console.log(chalk.bold('Gradient Complete!')); diff --git a/examples/theme.js b/examples/theme.js new file mode 100644 index 0000000..e4dcf71 --- /dev/null +++ b/examples/theme.js @@ -0,0 +1,34 @@ +import chalk from '../source/index.js'; + +// Set color level to enable colors (adjust based on terminal support) +chalk.level = 3; + +// Define a custom theme with named styles +const themedChalk = chalk.theme({ + error: chalk.red.bold, + success: chalk.green, + warning: chalk.yellow.underline, + info: chalk.blue, + title: chalk.magenta.bold.underline, +}); + +// Demonstrate the theme in action +console.log(themedChalk.title('Chalk Theme Example')); +console.log(); // Empty line + +console.log(themedChalk.error('This is an error message')); +console.log(themedChalk.success('This is a success message')); +console.log(themedChalk.warning('This is a warning message')); +console.log(themedChalk.info('This is an info message')); +console.log(); // Empty line + +// Show that original styles still work +console.log(themedChalk.red('Still works with original styles')); +console.log(themedChalk.bold('Bold text from themed chalk')); + +// Demonstrate chaining with theme styles +console.log(themedChalk.error.bgWhite('Error on white background')); +console.log(themedChalk.success.underline('Underlined success')); + +console.log(); +console.log(themedChalk.title('Theme Complete!')); diff --git a/readme.md b/readme.md old mode 100644 new mode 100755 index ce1f3f3..2d531af --- a/readme.md +++ b/readme.md @@ -27,6 +27,8 @@ - No dependencies - Ability to nest styles - [256/Truecolor color support](#256-and-truecolor-color-support) +- [Themes](#themes) for consistent styling +- [Gradients](#gradients) for smooth color transitions - Auto-detects color support - Doesn't extend `String.prototype` - Clean and focused @@ -87,18 +89,6 @@ log(chalk.rgb(123, 45, 67).underline('Underlined reddish color')); log(chalk.hex('#DEADED').bold('Bold gray!')); ``` -Easily define your own themes: - -```js -import chalk from 'chalk'; - -const error = chalk.bold.red; -const warning = chalk.hex('#FFA500'); // Orange color - -console.log(error('Error!')); -console.log(warning('Warning!')); -``` - Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args): ```js @@ -109,6 +99,40 @@ console.log(chalk.green('Hello %s'), name); //=> 'Hello Sindre' ``` +## Themes + +Define a theme with multiple styles for consistent coloring: + +```js +import chalk from 'chalk'; + +const themedChalk = chalk.theme({ + error: chalk.bold.red, + success: chalk.green, + warning: chalk.hex('#FFA500'), // Orange + info: chalk.blue, + title: chalk.cyan.bold.underline, +}); + +console.log(themedChalk.error('Error!')); +console.log(themedChalk.success('Success!')); +console.log(themedChalk.warning('Warning!')); +console.log(themedChalk.info('Info')); +console.log(themedChalk.title('Title')); +``` + +Themes work with all Chalk features including gradients and chaining: + +```js +const themedChalk = chalk.theme({ + rainbow: chalk.gradient('#ff0000', '#00ff00', '#0000ff'), + important: chalk.red.bold.underline, +}); + +console.log(themedChalk.rainbow('Rainbow text')); +console.log(themedChalk.important.bgWhite('Important message')); +``` + ## API ### chalk.`