pretty_print 1.0.0
pretty_print: ^1.0.0 copied to clipboard
A beautiful and customizable Dart library for printing colored and styled text to the terminal using ANSI escape codes. Perfect for CLI applications and debugging.
/// Example demonstrating all features of the pretty_print package.
///
/// This example showcases:
/// - All available colors
/// - Text styling options
/// - Background colors
/// - Special effects and animations
/// - Real-world use cases
///
/// Run this example with: dart run example/example.dart
library;
import 'package:pretty_print/pretty_print.dart';
void main() {
// Welcome header
_printHeader();
// Demonstrate all colors
_demonstrateColors();
// Demonstrate text styling
_demonstrateTextStyling();
// Demonstrate background colors
_demonstrateBackgroundColors();
// Demonstrate special effects
_demonstrateSpecialEffects();
// Show real-world use cases
_demonstrateUseCases();
// Footer
_printFooter();
}
/// Prints a welcome header with styling
void _printHeader() {
print('\n');
PrettyPrint.pprint(
"========================================",
textColor: PrintColor.cyan,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
" π¨ PRETTY PRINT DEMO π¨ ",
textColor: PrintColor.white,
backColor: PrintColor.blue,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
"========================================",
textColor: PrintColor.cyan,
textWeight: TextWeight.bold,
);
print('');
}
/// Demonstrates all available text colors
void _demonstrateColors() {
PrettyPrint.pprint(
"π¨ TEXT COLORS DEMONSTRATION",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
print('');
final colors = [
(PrintColor.black, "Black"),
(PrintColor.red, "Red"),
(PrintColor.green, "Green"),
(PrintColor.yellow, "Yellow"),
(PrintColor.blue, "Blue"),
(PrintColor.magenta, "Magenta"),
(PrintColor.cyan, "Cyan"),
(PrintColor.white, "White"),
];
for (final (color, name) in colors) {
PrettyPrint.pprint("β $name text", textColor: color);
}
print('');
}
/// Demonstrates text styling options
void _demonstrateTextStyling() {
PrettyPrint.pprint(
"β¨ TEXT STYLING DEMONSTRATION",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
print('');
PrettyPrint.pprint("Normal text weight", textWeight: TextWeight.normal);
PrettyPrint.pprint("Bold text weight", textWeight: TextWeight.bold);
PrettyPrint.pprint("Italic text style", textItalic: TextItalic.italic);
PrettyPrint.pprint("Underlined text", textUnderline: TextUnderLine.underline);
PrettyPrint.pprint("Strikethrough text", textDone: TextDone.done);
// Combined styling
PrettyPrint.pprint(
"Bold + Italic + Underlined",
textWeight: TextWeight.bold,
textItalic: TextItalic.italic,
textUnderline: TextUnderLine.underline,
textColor: PrintColor.magenta,
);
print('');
}
/// Demonstrates background colors
void _demonstrateBackgroundColors() {
PrettyPrint.pprint(
"πΌοΈ BACKGROUND COLORS DEMONSTRATION",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
print('');
final backgrounds = [
(PrintColor.black, PrintColor.white, "Black Background"),
(PrintColor.red, PrintColor.white, "Red Background"),
(PrintColor.green, PrintColor.white, "Green Background"),
(PrintColor.yellow, PrintColor.black, "Yellow Background"),
(PrintColor.blue, PrintColor.white, "Blue Background"),
(PrintColor.magenta, PrintColor.white, "Magenta Background"),
(PrintColor.cyan, PrintColor.black, "Cyan Background"),
(PrintColor.white, PrintColor.black, "White Background"),
];
for (final (backColor, textColor, text) in backgrounds) {
PrettyPrint.pprint(
" $text ",
textColor: textColor,
backColor: backColor,
textWeight: TextWeight.bold,
);
}
print('');
}
/// Demonstrates special effects and animations
void _demonstrateSpecialEffects() {
PrettyPrint.pprint(
"π SPECIAL EFFECTS DEMONSTRATION",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
print('');
PrettyPrint.pprint(
"Semi-transparent text",
textColor: PrintColor.white,
textAlphaAnim: AlphaAndAnim.semiOpacity,
);
PrettyPrint.pprint(
"Slow blinking animation",
textColor: PrintColor.red,
textAlphaAnim: AlphaAndAnim.slowAnim,
);
PrettyPrint.pprint(
"Fast blinking animation",
textColor: PrintColor.green,
textAlphaAnim: AlphaAndAnim.fastAnim,
);
print("Hidden text (next line is invisible):");
PrettyPrint.pprint("This text is hidden!", textAlphaAnim: AlphaAndAnim.hide);
print('');
}
/// Demonstrates real-world use cases
void _demonstrateUseCases() {
PrettyPrint.pprint(
"π REAL-WORLD USE CASES",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
print('');
// Status messages
print("π 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,
);
PrettyPrint.pprint(
" βΉ INFO ",
textColor: PrintColor.white,
backColor: PrintColor.blue,
textWeight: TextWeight.bold,
);
print('');
// Progress indicators
print("π Progress Indicators:");
PrettyPrint.pprint(
"π Loading data...",
textColor: PrintColor.cyan,
textAlphaAnim: AlphaAndAnim.slowAnim,
);
PrettyPrint.pprint(
"β
Task completed successfully",
textColor: PrintColor.green,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint("π Processing files...", textColor: PrintColor.yellow);
print('');
// Debug information
print("π Debug Information:");
PrettyPrint.pprint(
"[DEBUG] Application started",
textColor: PrintColor.blue,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
"[INFO] User logged in: john@example.com",
textColor: PrintColor.cyan,
);
PrettyPrint.pprint(
"[WARN] Deprecated function called",
textColor: PrintColor.yellow,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
"[ERROR] Failed to connect to database",
textColor: PrintColor.red,
textWeight: TextWeight.bold,
);
print('');
// CLI interface elements
print("π» CLI Interface Elements:");
PrettyPrint.pprint(
r"$ Command executed successfully",
textColor: PrintColor.green,
);
PrettyPrint.pprint(
"> User input prompt",
textColor: PrintColor.white,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
"β Step 1: Initialize project",
textColor: PrintColor.cyan,
);
PrettyPrint.pprint(
"β Step 2: Install dependencies",
textColor: PrintColor.green,
textDone: TextDone.done,
);
print('');
}
/// Prints a closing footer
void _printFooter() {
PrettyPrint.pprint(
"========================================",
textColor: PrintColor.cyan,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
" Demo completed! π ",
textColor: PrintColor.white,
backColor: PrintColor.green,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
" Thanks for using pretty_print! β€οΈ ",
textColor: PrintColor.magenta,
textWeight: TextWeight.bold,
);
PrettyPrint.pprint(
"========================================",
textColor: PrintColor.cyan,
textWeight: TextWeight.bold,
);
print('');
// Instructions
print(
"Try modifying the examples above to experiment with different combinations!",
);
print("Visit: https://pub.flutter-io.cn/packages/pretty_print for documentation");
print("GitHub: https://github.com/mohamedmaher-dev/pretty_print");
}