π¨ Pretty Print
A beautiful and customizable Dart library for printing colored and styled text to the terminal using ANSI escape codes. Perfect for CLI applications, debugging, and adding visual flair to your console output!
β¨ Features
- π¨ 8 Beautiful Colors: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
- πΌοΈ Background Colors: Apply any color as background
- π Text Styling: Bold, Italic, Underline, Strikethrough
- β¨ Special Effects: Blinking animations, opacity control, hidden text
- π Easy to Use: Simple, intuitive API with sensible defaults
- π Cross-Platform: Works on Windows, macOS, and Linux terminals
- π¦ Zero Dependencies: Lightweight and fast
- π― Type Safe: Full Dart type safety with enums
π Getting Started
Add this to your package's pubspec.yaml
file:
dependencies:
pretty_print: ^1.0.0
Then run:
dart pub get
π Usage
Import the package:
import 'package:pretty_print/pretty_print.dart';
Basic Examples
// Simple colored text
PrettyPrint.pprint("Hello World!", textColor: PrintColor.green);
// Bold text
PrettyPrint.pprint("Important!", textWeight: TextWeight.bold);
// Text with background color
PrettyPrint.pprint(" SUCCESS ",
textColor: PrintColor.white,
backColor: PrintColor.green
);
Advanced Styling
// Combine multiple styles
PrettyPrint.pprint("Warning!",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
textUnderline: TextUnderLine.underline
);
// Animated text
PrettyPrint.pprint("Loading...",
textColor: PrintColor.cyan,
textAlphaAnim: AlphaAndAnim.slowAnim
);
// Italic text with background
PrettyPrint.pprint("Stylish text",
textColor: PrintColor.white,
backColor: PrintColor.magenta,
textItalic: TextItalic.italic
);
Common Use Cases
Success/Error Messages
// Success message
PrettyPrint.pprint(" β SUCCESS ",
textColor: PrintColor.white,
backColor: PrintColor.green,
textWeight: TextWeight.bold
);
// Error message
PrettyPrint.pprint(" β ERROR ",
textColor: PrintColor.white,
backColor: PrintColor.red,
textWeight: TextWeight.bold
);
// Warning message
PrettyPrint.pprint(" β WARNING ",
textColor: PrintColor.black,
backColor: PrintColor.yellow,
textWeight: TextWeight.bold
);
Progress Indicators
// Loading with animation
PrettyPrint.pprint("π Loading...",
textColor: PrintColor.cyan,
textAlphaAnim: AlphaAndAnim.slowAnim
);
// Completed task
PrettyPrint.pprint("β
Task completed",
textColor: PrintColor.green,
textDone: TextDone.done // Strikethrough
);
Debug Information
// Debug info
PrettyPrint.pprint("[DEBUG]",
textColor: PrintColor.blue,
textWeight: TextWeight.bold
);
// Info message
PrettyPrint.pprint("[INFO]",
textColor: PrintColor.cyan
);
// Hidden sensitive data
PrettyPrint.pprint("Secret: password123",
textAlphaAnim: AlphaAndAnim.hide
);
π¨ Available Options
Colors (PrintColor
)
PrintColor.black
PrintColor.red
PrintColor.green
PrintColor.yellow
PrintColor.blue
PrintColor.magenta
PrintColor.cyan
PrintColor.white
PrintColor.none
(default)
Text Weight (TextWeight
)
TextWeight.normal
TextWeight.bold
TextWeight.none
(default)
Text Styling
TextItalic.italic
/TextItalic.none
TextUnderLine.underline
/TextUnderLine.none
TextDone.done
(strikethrough) /TextDone.none
Special Effects (AlphaAndAnim
)
AlphaAndAnim.semiOpacity
- Semi-transparent textAlphaAndAnim.hide
- Hidden textAlphaAndAnim.slowAnim
- Slow blinkingAlphaAndAnim.fastAnim
- Fast blinkingAlphaAndAnim.none
(default)
π― Complete Example
import 'package:pretty_print/pretty_print.dart';
void main() {
// Header
PrettyPrint.pprint("=== PRETTY PRINT DEMO ===",
textColor: PrintColor.white,
backColor: PrintColor.blue,
textWeight: TextWeight.bold
);
// Colors demonstration
print("\nπ¨ Colors:");
PrettyPrint.pprint("Red", textColor: PrintColor.red);
PrettyPrint.pprint("Green", textColor: PrintColor.green);
PrettyPrint.pprint("Blue", textColor: PrintColor.blue);
PrettyPrint.pprint("Yellow", textColor: PrintColor.yellow);
// Styling demonstration
print("\n⨠Styles:");
PrettyPrint.pprint("Bold text", textWeight: TextWeight.bold);
PrettyPrint.pprint("Italic text", textItalic: TextItalic.italic);
PrettyPrint.pprint("Underlined text", textUnderline: TextUnderLine.underline);
// Effects demonstration
print("\nπ Effects:");
PrettyPrint.pprint("Blinking text", textAlphaAnim: AlphaAndAnim.slowAnim);
PrettyPrint.pprint("Semi-transparent", textAlphaAnim: AlphaAndAnim.semiOpacity);
// Status messages
print("\nπ Status Messages:");
PrettyPrint.pprint(" SUCCESS ",
textColor: PrintColor.white,
backColor: PrintColor.green,
textWeight: TextWeight.bold
);
PrettyPrint.pprint(" WARNING ",
textColor: PrintColor.black,
backColor: PrintColor.yellow,
textWeight: TextWeight.bold
);
PrettyPrint.pprint(" ERROR ",
textColor: PrintColor.white,
backColor: PrintColor.red,
textWeight: TextWeight.bold
);
}
π οΈ Terminal Compatibility
This package works with most modern terminals that support ANSI escape codes:
- β Windows: Windows Terminal, PowerShell, Command Prompt (Windows 10+)
- β macOS: Terminal.app, iTerm2, and other terminal emulators
- β Linux: GNOME Terminal, Konsole, xterm, and most terminal emulators
- β IDEs: VS Code integrated terminal, IntelliJ terminal, and others
π€ Contributing
Contributions are welcome! If you have suggestions, bug reports, or want to contribute code:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some 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.
π¨βπ» Author
Mohamed Maher - GitHub
- π§ Email: mohamedmaher.personal@gmail.com
- πΌ LinkedIn: Mohamed Maher
- π Portfolio: Portfolio Website
β Support
If you like this package, please give it a β on GitHub and a π on pub.flutter-io.cn!
π More Packages
Check out my other packages:
id_generator
- Generate secure, customizable random IDseasy_in_app_notify
- Beautiful in-app notifications for Fluttermena
- Middle East and North Africa country data utilities
Made with β€οΈ by Mohamed Maher
Libraries
- pretty_print
- A beautiful and customizable Dart library for printing colored and styled text to the terminal.