A flexible Go library for creating beautiful ASCII tables with box-drawing characters and advanced formatting options.
- π Smart text wrapping and word splitting
- π Column alignment control (left, right, center)
- π Description support with optional titles
- β¨ Header highlighting
- π¨ Dim border styling for subtle tables
- π Table grouping for consistent column widths
- π Dynamic width adjustment and terminal detection
- π Support for borderless mode
- π‘ Fill width option for full terminal utilization
go get github.com/rapidfort/table
package main
import (
"fmt"
"github.com/rapidfort/table"
)
func main() {
// Create a table
tbl := table.RapidFortTable([]string{"Name", "Age", "City"})
// Add rows
tbl.AddRow([]string{"Alice", "30", "New York"})
tbl.AddRow([]string{"Bob", "25", "San Francisco"})
// Add description to a row
tbl.AddDescription(0, "Special customer discount applied")
// Render and print
fmt.Println(tbl.Render())
}
This produces:
βββββββββ¬ββββββ¬ββββββββββββββββ
β Name β Age β City β
βββββββββΌββββββΌββββββββββββββββ€
β Alice β 30 β New York β
β βββββββ΄ββββββββββββββββ€
β β β’ Special β
β β customer β
β β discount β
β β applied β
βββββββββΌββββββ¬ββββββββββββββββ€
β Bob β 25 β San Francisco β
βββββββββ΄ββββββ΄ββββββββββββββββ
// Highlight specific headers
tbl.SetHighlightedHeaders([]int{0, 2}) // Highlights columns 0 and 2
// Always highlight all headers (bold style)
tbl.SetHeaderHighlighting(true)
// Add/remove highlighting dynamically
tbl.AddHighlightedHeader(1)
tbl.ClearHighlightedHeaders()
// Enable dim borders (light gray)
tbl.SetDimBorder(true)
// Remove borders completely
tbl.SetBorderless(true)
// Automatic terminal width detection (default)
tbl.SetConsoleWidth(80) // Manual override
// Set column alignment
tbl.SetAlignment(0, "left") // Column 0: left-aligned
tbl.SetAlignment(1, "right") // Column 1: right-aligned
tbl.SetAlignment(2, "center") // Column 2: center-aligned
// Set maximum column widths
tbl.SetMaxWidth(1, 20) // Column 1 max width: 20 chars
// Enable width filling
tbl.SetFillWidth(true) // Expand to fill terminal width
When multiple tables need consistent column widths:
group := table.NewGroup()
// Create tables
table1 := table.RapidFortTable(headers)
table2 := table.RapidFortTable(headers)
// Add to group
group.Add(table1)
group.Add(table2)
// Sync column widths across all tables
group.SyncColumnWidths()
// Render tables with consistent widths
fmt.Println(table1.Render())
fmt.Println(table2.Render())
// Add description with title
tbl.AddDescriptionWithTitle(rowIndex, "Advisory", "High demand item, consider restocking")
// Add simple description
tbl.AddDescription(rowIndex, "This item is currently on backorder")
// Multi-line descriptions are automatically wrapped
tbl.AddDescription(rowIndex, "This is a long description that will wrap across multiple lines based on the available space in the table")
// Create table with all features
tbl := table.RapidFortTable([]string{"ID", "Product", "Stock", "Status"})
// Configure styling
tbl.SetDimBorder(true)
tbl.SetHighlightedHeaders([]int{1, 3})
tbl.SetAlignment(2, "right")
tbl.SetMaxWidth(1, 15)
// Add data
tbl.AddRow([]string{"001", "Wireless Mouse", "125", "Active"})
tbl.AddRow([]string{"002", "USB-C Hub Pro", "25", "Low Stock"})
tbl.AddRow([]string{"003", "Mechanical Keyboard", "50", "Active"})
// Add descriptions
tbl.AddDescriptionWithTitle(1, "Alert", "Reorder soon to avoid stockout")
tbl.AddDescription(2, "Popular item, high demand expected")
fmt.Println(tbl.Render())
tbl := table.RapidFortTable([]string{"Name", "Value"})
tbl.SetBorderless(true)
tbl.AddRow([]string{"Setting 1", "Enabled"})
tbl.AddRow([]string{"Setting 2", "Disabled"})
fmt.Println(tbl.Render())
For detailed API documentation, visit pkg.go.dev.
- Go 1.16 or higher
- Dependencies:
golang.org/x/term
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
MIT License
Copyright (c) 2025 RapidFort
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Built by the RapidFort team.