feat: add gradient and theme features with corresponding tests and documentation

This commit is contained in:
HarshaVardhan 2026-02-01 17:12:54 -05:00
parent aa06bb5ac3
commit c017dd5b04
8 changed files with 505 additions and 13 deletions

39
examples/gradient.js Normal file
View file

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

34
examples/theme.js Normal file
View file

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