dchalky 0.0.2
dchalky: ^0.0.2 copied to clipboard
A simple and elegant way to add colors and styles to your Dart/Flutter console logs, inspired by Chalk.js
๐จ dchalky #
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:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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:
- ๐ค Twitter: @neryadg
- ๐ฃ Twitch: twitch.tv/neryad
- ๐ More Links: beacons.ai/neryad
๐ Changelog #
See CHANGELOG.md for a detailed list of changes.
Made with โค๏ธ by Neryad
If you found this helpful, give it a โญ!