๐ŸŽจ dchalky

Pub Version License: MIT

A simple and elegant way to add colors and styles to your Dart/Flutter console logs. Inspired by the popular Chalk.js library, dchalky brings beautiful terminal output to your Dart projects with a clean, chainable API.

โœจ Features

  • ๐ŸŽจ 16 Colors: 8 standard + 8 bright colors for text
  • ๐ŸŒˆ Background Colors: Full color palette for backgrounds
  • ๐Ÿ’… Text Styles: Bold, italic, underline, strikethrough, and more
  • โ›“๏ธ Chainable API: Combine colors and styles effortlessly
  • ๐Ÿ”Œ Zero Dependencies: Lightweight and fast
  • ๐Ÿš€ Easy to Use: Intuitive syntax, familiar to Chalk.js users
  • ๐ŸŽฏ Global Control: Enable/disable colors globally for production

๐Ÿš€ Quick Start

Installation

Add to your pubspec.yaml:

dependencies:
  dchalky: ^0.0.2

Then run:

dart pub get

Basic Usage

import 'package:dchalky/dchalky.dart';

void main() {
  // Simple colors
  print(chalk.red('Error!'));
  print(chalk.green('Success!'));
  print(chalk.blue('Info'));

  // Combine styles
  print(chalk.red.bold('Critical Error!'));
  print(chalk.green.underline('Link'));

  // Background colors
  print(chalk.bgRed.white('Alert'));
  print(chalk.bgGreen.black('Success'));

  // Chain multiple styles
  print(chalk.blue.bold.underline('Important Info'));
}

๐Ÿ“– API Reference

Text Colors

Color Usage Bright Variant
Black chalk.black('text') -
Red chalk.red('text') chalk.brightRed()
Green chalk.green('text') chalk.brightGreen()
Yellow chalk.yellow('text') chalk.brightYellow()
Blue chalk.blue('text') chalk.brightBlue()
Magenta chalk.magenta('text') chalk.brightMagenta()
Cyan chalk.cyan('text') chalk.brightCyan()
White chalk.white('text') chalk.brightWhite()
Gray chalk.gray('text') -

Background Colors

All text colors are available as background colors with the bg prefix:

chalk.bgRed('text')
chalk.bgGreen('text')
chalk.bgBlue('text')
// ... and bright variants
chalk.bgBrightRed('text')

Text Styles

Style Usage Description
Bold chalk.bold('text') Bold or increased intensity
Dim chalk.dim('text') Decreased intensity
Italic chalk.italic('text') Italic text
Underline chalk.underline('text') Underlined text
Inverse chalk.inverse('text') Swap foreground/background
Strikethrough chalk.strikethrough('text') Crossed-out text

๐ŸŽฎ Real-World Examples

Log Levels

print(chalk.green('โœ“ Success: User authenticated'));
print(chalk.red('โœ— Error: Connection timeout'));
print(chalk.yellow('โš  Warning: Low memory'));
print(chalk.blue('โ„น Info: Loading data...'));
print(chalk.gray('๐Ÿ” Debug: x = 42'));

Structured Logs

final timestamp = chalk.gray('[2025-01-17 10:30:45]');
final level = chalk.green.bold('SUCCESS');
final message = 'User login completed';

print('$timestamp $level $message');

Error Messages

void showError(String message) {
  print(chalk.bgRed.white.bold(' ERROR '));
  print(chalk.red(message));
}

showError('File not found: config.json');

Progress Indicators

print(chalk.cyan('โณ Processing...'));
// ... do work ...
print(chalk.green('โœ“ Complete!'));

๐Ÿ”ง Advanced Features

Global Enable/Disable

Perfect for production environments where you want to disable colors:

void main() {
  // Disable colors in production
  if (const bool.fromEnvironment('dart.vm.product')) {
    Chalk.enabled = false;
  }

  print(chalk.red('This will only be red in development'));
}

Custom Helpers

Create your own helper functions:

String success(String msg) => chalk.green('โœ“ $msg');
String error(String msg) => chalk.red('โœ— $msg');
String warning(String msg) => chalk.yellow('โš  $msg');

print(success('Operation completed'));
print(error('Something went wrong'));

๐ŸŽฏ Use Cases

  • Development Logging: Make your debug output easier to read
  • CLI Tools: Create beautiful command-line applications
  • Build Scripts: Highlight important build information
  • Test Runners: Color-code test results
  • Dev Tools: Improve developer experience with visual feedback

๐Ÿงช Testing

# Run tests
flutter test

# Check coverage
flutter test --coverage

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐ŸŒŸ Support

If dchalky has helped improve your development experience, consider:

  • โญ Starring the repo
  • ๐Ÿ› Reporting bugs
  • ๐Ÿ’ก Suggesting features
  • ๐Ÿ“– Improving documentation

๐Ÿ“ฑ Connect

Follow for updates and more Dart/Flutter tools:

ko-fi

๐Ÿ“ˆ Changelog

See CHANGELOG.md for a detailed list of changes.


Made with โค๏ธ by Neryad

If you found this helpful, give it a โญ!

Libraries

dchalky