π¨ 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!
πΌοΈ Visual Showcase
π¨ Colors & Text Styling | π Status Messages & Extensions | π Advanced Formatting & Effects |
---|---|---|
![]() |
![]() |
![]() |
π Try it yourself: Run
dart run example/example.dart
to see all features in action!
β¨ 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, Blinking
- π 75+ Extension Methods: Organized into logical groups for easy discovery
- π§ Grouped API: Methods organized by category (logging, styling, colors, formatting, debug)
- π Advanced Formatting: Boxes, headers, separators, alignment, lists
- π Development Tools: Debugging utilities, variable inspection, performance monitoring
- π Special Effects: Rainbow text, animations, and visual enhancements
- π 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: ^2.1.0
Then run:
dart pub get
π Usage
Import the package:
import 'package:pretty_print/pretty_print.dart';
π― Grouped Extension API (v2.1.0+)
The new grouped extension system organizes methods into logical categories for better discoverability and cleaner code:
π Logging Methods
// Status logging with styled headers
"Operation completed successfully!".logging.successLog();
"Application started".logging.infoLog();
"This feature is deprecated".logging.warningLog();
"Failed to connect to database".logging.errorLog();
"Debugging user authentication".logging.debugLog();
"Critical system failure".logging.criticalLog();
"Entering function".logging.traceLog();
"Database query took 150ms".logging.performanceLog();
π Text Styling Methods
// Text styling and effects
"Bold text".styling.bold();
"Italic text".styling.italic();
"Underlined text".styling.underline();
"Strikethrough text".styling.lineThrough();
"Blinking text".styling.blink();
"Bold + Underlined".styling.boldUnderline();
"All effects combined".styling.allEffects();
π Color Methods
// Text colors
"Red text".colors.red();
"Green text".colors.green();
"Blue text".colors.blue();
"Yellow text".colors.yellow();
// Background colors
"Text on red background".colors.onRed();
"Text on green background".colors.onGreen();
"Text on blue background".colors.onBlue();
// Combined styling
"Bold red text".colors.boldRed();
"Bold green text".colors.boldGreen();
// Special effects
"Rainbow text!".colors.rainbow();
π Formatting Methods
// Layout and formatting
"Title".formatting.header();
"Content".formatting.box();
"Double border content".formatting.doubleBox();
// Lists and bullets
"First item".formatting.bullet();
"Second item".formatting.bullet();
"Step 1".formatting.numbered(1);
"Step 2".formatting.numbered(2);
// Alignment
"Left aligned text".formatting.leftAlign(30);
"Right aligned text".formatting.rightAlign(30);
"Centered text".formatting.center(30);
// Text formatting
"Important quote".formatting.quote();
"console.log('Hello')".formatting.code();
"Indented text".formatting.indent(2);
// Separators
"".formatting.separator();
// Utility methods
"Message".formatting.withPrefix(">>> ");
"Alert".formatting.withSuffix(" <<<");
π Debug Methods
// Development and debugging
"Variable inspection".debug.debugPrint();
"Fix this later".debug.todo();
"This needs attention".debug.fixme();
"Important note".debug.note();
"API response data".debug.inspect();
// Performance monitoring
"Performance check".debug.benchmark();
"Memory usage".debug.memory();
"Network request status".debug.network();
"Database query result".debug.database();
// Variable inspection
"userName".debug.variable("john_doe");
"age".debug.variable(25);
"isActive".debug.variable(true);
// Development status
"User authentication passed".debug.assertion();
"Legacy method usage".debug.deprecated();
"Experimental feature active".debug.experimental();
"Security check passed".debug.security();
"Configuration loaded".debug.config();
π§ Basic PrettyPrint.log Usage
For direct control over styling, you can still use the traditional PrettyPrint.log
method:
// Simple colored text
PrettyPrint.log("Hello World!", textColor: PrintColor.green);
// Text with background and styling
PrettyPrint.log(
" SUCCESS ",
textColor: PrintColor.white,
backColor: PrintColor.green,
textWeight: TextWeight.bold,
);
// Combined effects
PrettyPrint.log(
"Important Notice",
textColor: PrintColor.red,
textWeight: TextWeight.bold,
textUnderline: TextUnderLine.underline,
textBlink: TextBlink.slowBlink,
);
π― Why Use Grouped Extensions?
The new grouped extension system provides several benefits:
- π Better Discoverability: IDE autocomplete shows only relevant methods for each category
- π Organized Code: Methods are logically grouped by functionality
- π§Ή Cleaner API: Reduces namespace pollution
- π Enhanced Productivity: Find the right method faster
- π Better Documentation: Each group is clearly documented
Migration Example
// Old API (still works)
"Success message".successLog();
"Bold text".bold();
"Red text".red();
// New API (recommended)
"Success message".logging.successLog();
"Bold text".styling.bold();
"Red text".colors.red();
π¨ Advanced Usage Examples
Complex Formatting
// Create professional-looking output
"System Status Report".formatting.header();
"".formatting.separator();
"CPU Usage: 45%".debug.benchmark();
"Memory: 256MB".debug.memory();
"Network: Connected".debug.network();
"Database: Online".debug.database();
"".formatting.separator();
"All systems operational".logging.successLog();
CLI Application Example
// Application startup
"π MyApp v1.0.0".formatting.header();
// Progress indicators
"[1/4] Initializing...".logging.infoLog();
"[2/4] Loading config...".logging.infoLog();
"[3/4] Connecting to database...".logging.infoLog();
"[4/4] Ready!".logging.successLog();
// User interactions
"Enter your name: ".colors.cyan();
// ... get user input
"Welcome, John!".logging.successLog();
// Error handling
if (error) {
"Connection failed: ${error.message}".logging.errorLog();
"Please check your network settings".logging.warningLog();
}
Development & Debugging
// Variable inspection
"userName".debug.variable(currentUser.name);
"isAuthenticated".debug.variable(user.isAuth);
"requestCount".debug.variable(stats.requests);
// Performance monitoring
"Database query completed".debug.benchmark();
"Memory usage: ${getMemoryUsage()}MB".debug.memory();
"API response time: ${responseTime}ms".debug.network();
// Development notes
"TODO: Implement caching".debug.todo();
"FIXME: Handle edge case".debug.fixme();
"NOTE: This is a temporary solution".debug.note();
π Common Use Cases
Status Messages
// Using grouped extensions (recommended)
"Operation completed successfully".logging.successLog();
"Loading user preferences".logging.infoLog();
"API endpoint deprecated".logging.warningLog();
"Connection failed".logging.errorLog();
"System debug info".logging.debugLog();
Professional CLI Output
"π Application Startup".formatting.header();
"Loading configuration...".logging.infoLog();
"Database connected".logging.successLog();
"π System Status".formatting.box();
"CPU: 45%".debug.benchmark();
"Memory: 256MB".debug.memory();
"Connections: 1,247".debug.network();
Development & Debugging
"Add user authentication".debug.todo();
"Fix memory leak in cache".debug.fixme();
"Performance looks good".debug.note();
"userId".debug.variable("user_123");
"isAuthenticated".debug.variable(true);
"responseTime".debug.variable("89ms");
Professional Output
"Application Report".formatting.header();
"".formatting.separator();
"System Metrics".formatting.leftAlign(20);
"Status: Online".formatting.rightAlign(15, PrintColor.green);
"Last Updated".formatting.leftAlign(20);
DateTime.now().toString().formatting.rightAlign(25, PrintColor.cyan);
π API Reference
π§ Extension Groups
.logging
- Status Logging Methods
successLog()
- Green success message with β iconinfoLog()
- Blue info message with βΉ iconwarningLog()
- Yellow warning message with β iconerrorLog()
- Red error message with β icondebugLog()
- Magenta debug message with π iconcriticalLog()
- Red blinking critical message with π¨ icontraceLog()
- Cyan trace message with π iconperformanceLog()
- Yellow performance message with β‘ icon
.styling
- Text Styling Methods
bold([color])
- Bold text with optional coloritalic([color])
- Italic text with optional colorunderline([color])
- Underlined text with optional colorlineThrough([color])
- Strikethrough text with optional colorblink([color])
- Blinking text with optional colorfastBlink([color])
- Fast blinking text with optional colordim([color])
- Dimmed text with optional colorhide()
- Hidden textboldUnderline([color])
- Combined bold and underlineitalicUnderline([color])
- Combined italic and underlineallEffects([color])
- All text effects combined
.colors
- Color Methods
Text Colors:
black()
,red()
,green()
,yellow()
,blue()
,magenta()
,cyan()
,white()
Background Colors:
onBlack()
,onRed()
,onGreen()
,onYellow()
,onBlue()
,onMagenta()
,onCyan()
,onWhite()
Combined Colors:
boldRed()
,boldGreen()
,boldBlue()
,boldYellow()
,boldMagenta()
,boldCyan()
,boldWhite()
Special Effects:
rainbow()
- Rainbow colored text
.formatting
- Layout & Formatting Methods
Containers:
header([color])
- Header with decorative bordersbox([borderColor])
- Single-line box around textdoubleBox([borderColor])
- Double-line box around text
Lists:
bullet([color])
- Bullet point (β’)numbered(number, [color])
- Numbered list item
Alignment:
leftAlign(width, [color])
- Left-aligned textrightAlign(width, [color])
- Right-aligned textcenter(width, [color])
- Centered text
Text Formatting:
quote([color])
- Quoted text with italic stylingcode([color])
- Code formatting with monospace backgroundindent(level)
- Indented text
Utilities:
separator([color])
- Horizontal separator linewithPrefix(prefix, [color])
- Add prefix to textwithSuffix(suffix, [color])
- Add suffix to text
.debug
- Development & Debugging Methods
Basic Debug:
debugPrint()
- Debug message with timestamptodo()
- TODO note with π iconfixme()
- FIXME note with π§ iconnote()
- General note with π iconinspect()
- Inspect data with π icon
Performance:
benchmark()
- Performance message with β±οΈ iconmemory()
- Memory usage with πΎ iconnetwork()
- Network status with π icondatabase()
- Database status with ποΈ icon
Development:
variable(value)
- Variable inspection with π’ iconassertion()
- Assertion message with β icondeprecated()
- Deprecation warning with β οΈ iconexperimental()
- Experimental feature with π§ͺ iconsecurity()
- Security message with π iconconfig()
- Configuration message with βοΈ icon
π¨ Available Colors
PrintColor.black
,PrintColor.red
,PrintColor.green
,PrintColor.yellow
PrintColor.blue
,PrintColor.magenta
,PrintColor.cyan
,PrintColor.white
π Text Styling Options
TextWeight.bold
/TextWeight.normal
TextItalic.italic
/TextItalic.none
TextUnderLine.underline
/TextUnderLine.none
TextThroughLine.lineThrough
/TextThroughLine.none
β¨ Special Effects
TextBlink.slowBlink
- Slow blinking animationTextBlink.fastBlink
- Fast blinking animationTextBlink.semiOpacity
- Semi-transparent textTextBlink.hide
- Hidden text
π Extension Categories (75+ Methods)
π Logging (8 methods)
successLog()
, infoLog()
, warningLog()
, errorLog()
, debugLog()
, criticalLog()
, traceLog()
, performanceLog()
π¨ Styling (12 methods)
bold()
, italic()
, underline()
, lineThrough()
, blink()
, fastBlink()
, dim()
, hide()
, boldUnderline()
, italicUnderline()
, allEffects()
π Colors (25+ methods)
red()
, green()
, blue()
, onRed()
, onGreen()
, boldRed()
, boldGreen()
, rainbow()
, etc.
π Formatting (16 methods)
header()
, box()
, doubleBox()
, separator()
, leftAlign()
, center()
, bullet()
, numbered()
, indent()
, quote()
, code()
, etc.
π Debug (16 methods)
todo()
, fixme()
, note()
, debugPrint()
, inspect()
, variable()
, benchmark()
, memory()
, network()
, security()
, etc.
// 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",
textBlink: TextBlink.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
TextThroughLine.lineThrough
(strikethrough) /TextThroughLine.none
Blinking and Opacity Effects (TextBlink
)
TextBlink.semiOpacity
- Semi-transparent textTextBlink.hide
- Hidden textTextBlink.slowBlink
- Slow blinkingTextBlink.fastBlink
- Fast blinkingTextBlink.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.log("Blinking text", textBlink: TextBlink.slowBlink);
PrettyPrint.log("Semi-transparent", textBlink: TextBlink.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.