mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
| datasource | package | from | to | | ---------- | ------------------------------- | ------ | ------ | | go | github.com/jedib0t/go-pretty/v6 | v6.7.5 | v6.7.8 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
6.3 KiB
6.3 KiB
Table
Pretty-print tables into ASCII/Unicode strings.
Sample Table Rendering
+---------------------------------------------------------------------+
| Game of Thrones +
+-----+------------+-----------+--------+-----------------------------+
| # | FIRST NAME | LAST NAME | SALARY | |
+-----+------------+-----------+--------+-----------------------------+
| 1 | Arya | Stark | 3000 | |
| 20 | Jon | Snow | 2000 | You know nothing, Jon Snow! |
| 300 | Tyrion | Lannister | 5000 | |
+-----+------------+-----------+--------+-----------------------------+
| | | TOTAL | 10000 | |
+-----+------------+-----------+--------+-----------------------------+
A demonstration of all the capabilities can be found here: ../cmd/demo-table
If you want very specific examples, look at the EXAMPLES.md file.
Features
Core Table Building
- Add Rows one-by-one or as a group (
AppendRow/AppendRows) - Add Header(s) and Footer(s) (
AppendHeader/AppendFooter) - Add a Separator manually after any Row (
AppendSeparator) - Add Title above the table (
SetTitle) - Add Caption below the table (
SetCaption) - Import 1D or 2D arrays/grids as rows (
ImportGrid) - Reset Headers/Rows/Footers at will to reuse the same Table Writer (
Reset*)
Indexing & Navigation
- Auto Index Rows (1, 2, 3 ...) and Columns (A, B, C, ...) (
SetAutoIndex) - Set which column is the index column (
SetIndexColumn) - Pager interface for navigating through paged output (
Pager())GoTo(pageNum)- Jump to specific pageNext()- Move to next pagePrev()- Move to previous pageLocation()- Get current page numberRender()- Render current pageSetOutputMirror()- Mirror output to io.Writer
Auto Merge
- Auto Merge cells (not supported in CSV/Markdown/TSV modes)
- Cells in a Row (
RowConfig.AutoMerge) - Columns (
ColumnConfig.AutoMerge) (not supported in HTML mode) - Custom alignment for merged cells (
RowConfig.AutoMergeAlign)
- Cells in a Row (
Size & Width Control
- Limit the length of Rows (
SetAllowedRowLengthorStyle().Size.WidthMax) - Auto-size Rows (
Style().Size.WidthMinandStyle().Size.WidthMax) - Column width control (
ColumnConfig.WidthMinandColumnConfig.WidthMax) - Custom width enforcement functions (
ColumnConfig.WidthMaxEnforcer)- Default:
text.WrapText - Options:
text.WrapSoft,text.WrapHard,text.Trim, or custom function
- Default:
Alignment
- Horizontal Alignment
- Auto (numeric columns aligned Right, text aligned Left)
- Custom per column (
ColumnConfig.Align,AlignHeader,AlignFooter) - Options: Left, Center, Right, Justify, Auto
- Vertical Alignment
- Custom per column with multi-line cell support (
ColumnConfig.VAlign,VAlignHeader,VAlignFooter) - Options: Top, Middle, Bottom
- Custom per column with multi-line cell support (
Sorting & Filtering
- Sorting
- Sort by one or more Columns (
SortBy) - Multiple column sorting support
- Various sort modes: Alphabetical, Numeric, Alpha-numeric, Numeric-alpha
- Case-insensitive sorting option (
IgnoreCase) - Custom sorting functions (
CustomLess) for advanced sorting logic
- Sort by one or more Columns (
- Filtering
- Filter by one or more Columns (
FilterBy) - Multiple filters with AND logic (all must match)
- Various filter operators:
- Equality: Equal, NotEqual
- Numeric: GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual
- String: Contains, NotContains, StartsWith, EndsWith
- Regex: RegexMatch, RegexNotMatch
- Case-insensitive filtering option (
IgnoreCase) - Custom filter functions (
CustomFilter) for advanced filtering logic - Filters are applied before sorting
- Filter by one or more Columns (
- Suppress/hide columns with no content (
SuppressEmptyColumns) - Hide specific columns (
ColumnConfig.Hidden) - Suppress trailing spaces in the last column (
SuppressTrailingSpaces)
Customization & Styling
- Row Coloring
- Custom row painter function (
SetRowPainter) - Row painter with attributes (
RowPainterWithAttributes) - Access to row number and sorted position
- Custom row painter function (
- Cell Transformation
- Customizable Cell rendering per Column (
ColumnConfig.Transformer,TransformerHeader,TransformerFooter) - Use built-in transformers from
textpackage (Number, JSON, Time, URL, etc.)
- Customizable Cell rendering per Column (
- Column Styling
- Per-column colors (
ColumnConfig.Colors,ColorsHeader,ColorsFooter) - Per-column alignment (horizontal and vertical)
- Per-column width constraints
- Per-column colors (
- Completely customizable styles (
SetStyle/Style)- Many ready-to-use styles: style.go
StyleDefault- Classic ASCII bordersStyleLight- Light box-drawing charactersStyleBold- Bold box-drawing charactersStyleDouble- Double box-drawing charactersStyleRounded- Rounded box-drawing charactersStyleColoredBright- Bright colors, no bordersStyleColoredDark- Dark colors, no borders- Many more colored variants (Blue, Cyan, Green, Magenta, Red, Yellow)
- Colorize Headers/Body/Footers using ../text/color.go
- Custom text-case for Headers/Body/Footers
- Enable/disable separators between rows
- Render table with or without borders
- Customize box-drawing characters
- Horizontal separators per section (title, header, rows, footer) using
BoxStyleHorizontal
- Horizontal separators per section (title, header, rows, footer) using
- Title and caption styling options
- HTML rendering options (CSS class, escaping, newlines, color conversion)
- Bidirectional text support (
Style().Format.Direction)
- Many ready-to-use styles: style.go
Output Formats
- Render as:
- (ASCII/Unicode) Table - Human-readable pretty format
- CSV - Comma-separated values
- HTML Table - With custom CSS Class and options
- Markdown Table - Markdown-compatible format
- TSV - Tab-separated values
- Mirror output to an
io.Writer(ex.os.StdOut) (SetOutputMirror)