tabprinter
tabprinter is a Rust library for creating and printing formatted tables in the terminal. It supports various table styles and offers both color and non-color output options.
Features
- Versatile Table Styles:
- 8 built-in styles: Simple, Grid, FancyGrid, Clean, Round, Banner, Block, and Amiga
- Support for both ASCII and Unicode border characters
- Flexible Content Handling:
- Customizable column widths (fixed, percentage-based, or auto)
- Text alignment options (Left, Right, Center)
- Multi-line cell content support
- Automatic text wrapping
- Advanced Formatting:
- Color output support via termcolor
- Bold, italic, and underline text formatting
- Custom cell background colors
- Output Options:
- Direct terminal output
- String conversion for further processing
- File export capabilities
- Developer-Friendly:
- Intuitive and easy-to-use API
- Minimal dependencies
- Comprehensive documentation and examples
Installation
Add this to your Cargo.toml:
[]
= "0.2.1"
Usage
Here's a basic example of how to use tabprinter:
use ;
This will output:
| | | |
| | | |
| | | |
Table Styles
tabprinter supports the following table styles:
Simple: No bordersGrid: ASCII bordersFancyGrid: Unicode bordersClean: Minimal bordersRound: Rounded cornersBanner: Top and bottom bannersBlock: Block-style bordersAmiga: Amiga-inspired style (color output only)
To change the style, simply use a different TableStyle when creating the table:
let mut table = new;
Color Output
To use color output, use the print_color method instead of print:
use ;
let mut stdout = stdout;
table.print_color.unwrap;
Examples
Check out the examples directory for more usage examples:
basic_usage.rs: Demonstrates basic table creation and printingdifferent_styles.rs: Shows all available table stylescustom_data.rs: Example of using custom data structures with tablescolor_output.rs: Demonstrates using colored output for tablescustom_formatting.rs: Shows how to apply custom formatting to table cellsdynamic_tables.rs: Examples of creating dynamically sized tablesfile_export.rs: How to export tables to files instead of stdoutcomplex_layouts.rs: Advanced table layout configurations
To run an example:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.