table

package module
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 8 Imported by: 14

README ยถ

table: Tables for terminals

This is a Go module for rendering tables in the terminal.

Features

  • โ†• Headers/footers
  • โ†ฉ Text wrapping
  • ๐Ÿ”€ Auto-merging of cells
  • โ‰ Customisable line/border characters
  • ๐ŸŒˆ Customisable line/border colours
  • โฏ Individually enable/disable borders, row lines
  • โ†” Set alignments on a per-column basis, with separate settings for headers/footers
  • ๐Ÿ“ Intelligently wrap/pad/measure ANSI coloured input
  • ๐Ÿ‘ฏ Support for double-width unicode characters
  • ๐Ÿ“Š Load data from CSV files

Check out the documentation for full features/usage.

Examples

Example: Basic
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Apple       โ”‚ 14     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2  โ”‚ Banana      โ”‚ 88,041 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3  โ”‚ Cherry      โ”‚ 342    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 4  โ”‚ Dragonfruit โ”‚ 1      โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: No Row Lines
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetRowLines(false)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Apple       โ”‚ 14     โ”‚
โ”‚ 2  โ”‚ Banana      โ”‚ 88,041 โ”‚
โ”‚ 3  โ”‚ Cherry      โ”‚ 342    โ”‚
โ”‚ 4  โ”‚ Dragonfruit โ”‚ 1      โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: No Borders
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetBorders(false)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
 ID โ”‚    Fruit    โ”‚ Stock  
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 1  โ”‚ Apple       โ”‚ 14     
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 2  โ”‚ Banana      โ”‚ 88,041 
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 3  โ”‚ Cherry      โ”‚ 342    
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 4  โ”‚ Dragonfruit โ”‚ 1      

Example: No Borders Or Row Lines
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetRowLines(false)
	t.SetBorders(false)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
 ID โ”‚    Fruit    โ”‚ Stock  
โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 1  โ”‚ Apple       โ”‚ 14     
 2  โ”‚ Banana      โ”‚ 88,041 
 3  โ”‚ Cherry      โ”‚ 342    
 4  โ”‚ Dragonfruit โ”‚ 1      

Example: Specific Borders
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetRowLines(false)
	t.SetBorderLeft(true)
	t.SetBorderRight(false)
	t.SetBorderTop(true)
	t.SetBorderBottom(false)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ 1  โ”‚ Apple       โ”‚ 14     
โ”‚ 2  โ”‚ Banana      โ”‚ 88,041 
โ”‚ 3  โ”‚ Cherry      โ”‚ 342    
โ”‚ 4  โ”‚ Dragonfruit โ”‚ 1      

Example: Footers
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)

	t.SetHeaders("ID", "Fruit", "Stock")
	t.SetFooters("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Apple       โ”‚ 14     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2  โ”‚ Banana      โ”‚ 88,041 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3  โ”‚ Cherry      โ”‚ 342    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 4  โ”‚ Dragonfruit โ”‚ 1      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Padding
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetPadding(5)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     ID     โ”‚        Fruit        โ”‚     Stock      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     1      โ”‚     Apple           โ”‚     14         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     2      โ”‚     Banana          โ”‚     88,041     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     3      โ”‚     Cherry          โ”‚     342        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     4      โ”‚     Dragonfruit     โ”‚     1          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Alignment
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetAlignment(table.AlignLeft, table.AlignCenter, table.AlignRight)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚    Apple    โ”‚     14 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2  โ”‚   Banana    โ”‚ 88,041 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3  โ”‚   Cherry    โ”‚    342 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 4  โ”‚ Dragonfruit โ”‚      1 โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Rounded Corners
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetDividers(table.UnicodeRoundedDividers)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ID โ”‚    Fruit    โ”‚ Stock  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ Apple       โ”‚ 14     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2  โ”‚ Banana      โ”‚ 88,041 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3  โ”‚ Cherry      โ”‚ 342    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 4  โ”‚ Dragonfruit โ”‚ 1      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Example: Custom Dividers
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)
	t.SetDividers(table.Dividers{
		ALL: "@",
		NES: "@",
		NSW: "@",
		NEW: "@",
		ESW: "@",
		NE:  "@",
		NW:  "@",
		SW:  "@",
		ES:  "@",
		EW:  "~",
		NS:  "!",
	})

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@
! ID !    Fruit    ! Stock  !
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@
! 1  ! Apple       ! 14     !
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@
! 2  ! Banana      ! 88,041 !
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@
! 3  ! Cherry      ! 342    !
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@
! 4  ! Dragonfruit ! 1      !
@~~~~@~~~~~~~~~~~~~@~~~~~~~~@

Example: Auto Merge Cells
package main

import (
	"os"
	"time"

	"github.com/khulnasoft-lab/table"
)

func main() {

	t := table.New(os.Stdout)

	t.SetAutoMerge(true)

	t.SetHeaders("System", "Status", "Last Check")

	t.AddRow("Life Support", "OK", time.Now().Format(time.Stamp))
	t.AddRow("Nuclear Generator", "OK", time.Now().Add(-time.Minute).Format(time.Stamp))
	t.AddRow("Weapons Systems", "FAIL", time.Now().Format(time.Stamp))
	t.AddRow("Shields", "OK", time.Now().Format(time.Stamp))

	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      System       โ”‚ Status โ”‚   Last Check    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Life Support      โ”‚ OK     โ”‚ May 13 17:34:32 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค        โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Nuclear Generator โ”‚        โ”‚ May 13 17:33:32 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Weapons Systems   โ”‚ FAIL   โ”‚ May 13 17:34:32 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค                 โ”‚
โ”‚ Shields           โ”‚ OK     โ”‚                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Load Data From Csv
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {

	f, err := os.Open("./_examples/12-load-data-from-csv/data.csv")
	if err != nil {
		panic(err)
	}

	t := table.New(os.Stdout)
	if err := t.LoadCSV(f, true); err != nil {
		panic(err)
	}
	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Id โ”‚    Date    โ”‚                  Message                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1  โ”‚ 2022-05-12 โ”‚ Hello world!                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2  โ”‚ 2022-05-12 โ”‚ These messages are loaded from a CSV file. โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 3  โ”‚ 2022-05-13 โ”‚ Incredible!                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Markdown Format
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {
	t := table.New(os.Stdout)
	t.SetDividers(table.MarkdownDividers)

	t.SetBorderTop(false)
	t.SetBorderBottom(false)
	t.SetRowLines(false)

	t.SetHeaders("ID", "Fruit", "Stock")

	t.AddRow("1", "Apple", "14")
	t.AddRow("2", "Banana", "88,041")
	t.AddRow("3", "Cherry", "342")
	t.AddRow("4", "Dragonfruit", "1")

	t.Render()
}

Output
| ID |    Fruit    | Stock  |
|----|-------------|--------|
| 1  | Apple       | 14     |
| 2  | Banana      | 88,041 |
| 3  | Cherry      | 342    |
| 4  | Dragonfruit | 1      |

Example: Header Colspans
package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {
	t := table.New(os.Stdout)
	t.SetHeaders("Namespace", "Resource", "Vulnerabilities", "Misconfigurations")
	t.AddHeaders("Namespace", "Resource", "Critical", "High", "Medium", "Low", "Unknown", "Critical", "High", "Medium", "Low", "Unknown")
	t.SetHeaderColSpans(0, 1, 1, 5, 5)
	t.SetAutoMergeHeaders(true)
	t.AddRow("default", "Deployment/app", "2", "5", "7", "8", "0", "0", "3", "5", "19", "0")
	t.AddRow("default", "Ingress/test", "-", "-", "-", "-", "-", "1", "0", "2", "17", "0")
	t.AddRow("default", "Service/test", "0", "0", "0", "1", "0", "3", "0", "4", "9", "0")
	t.Render()
}

Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Namespace โ”‚    Resource    โ”‚             Vulnerabilities              โ”‚            Misconfigurations             โ”‚
โ”‚           โ”‚                โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚           โ”‚                โ”‚ Critical โ”‚ High โ”‚ Medium โ”‚ Low โ”‚ Unknown โ”‚ Critical โ”‚ High โ”‚ Medium โ”‚ Low โ”‚ Unknown โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ default   โ”‚ Deployment/app โ”‚ 2        โ”‚ 5    โ”‚ 7      โ”‚ 8   โ”‚ 0       โ”‚ 0        โ”‚ 3    โ”‚ 5      โ”‚ 19  โ”‚ 0       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ default   โ”‚ Ingress/test   โ”‚ -        โ”‚ -    โ”‚ -      โ”‚ -   โ”‚ -       โ”‚ 1        โ”‚ 0    โ”‚ 2      โ”‚ 17  โ”‚ 0       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ default   โ”‚ Service/test   โ”‚ 0        โ”‚ 0    โ”‚ 0      โ”‚ 1   โ”‚ 0       โ”‚ 3        โ”‚ 0    โ”‚ 4      โ”‚ 9   โ”‚ 0       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Example: Double-width Unicode

package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
)

func main() {
	t := table.New(os.Stdout)
	t.SetHeaders("A", "B", "C")
	t.AddRow("๐Ÿ”ฅ unicode ๐Ÿ”ฅ characters ๐Ÿ”ฅ", "2", "3")
	t.AddRow("4", "5", "6")
	t.Render()
}

Example: ANSI Colours

package main

import (
	"os"

	"github.com/khulnasoft-lab/table"
	"github.com/liamg/tml"
)

func main() {

	t := table.New(os.Stdout)

	t.SetHeaders("ID", "Fruit", "Stock", "Description")
	t.SetHeaderStyle(table.StyleBold)
	t.SetLineStyle(table.StyleBlue)
	t.SetDividers(table.UnicodeRoundedDividers)

	t.AddRow("1", tml.Sprintf("<green>Apple</green>"), "14", tml.Sprintf("An apple is an edible fruit produced by an apple tree (<italic>Malus domestica</italic>). "))
	t.AddRow("2", tml.Sprintf("<yellow>Banana</yellow>"), "88,041", "A banana is an elongated, edible fruit - botanically a berry.")
	t.AddRow("3", tml.Sprintf("<red>Cherry</red>"), "342", "A cherry is the fruit of many plants of the genus Prunus, and is a fleshy drupe (stone fruit). ")
	t.AddRow("4", tml.Sprintf("<magenta>Dragonfruit</magenta>"), "1", "A dragonfruit is the fruit of several different cactus species indigenous to the Americas.")

	t.Render()
}

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

View Source
var ASCIIDividers = Dividers{
	ALL: "+",
	NES: "+",
	NSW: "+",
	NEW: "+",
	ESW: "+",
	NE:  "+",
	NW:  "+",
	SW:  "+",
	ES:  "+",
	EW:  "-",
	NS:  "|",
}
View Source
var MarkdownDividers = Dividers{
	ALL: "|",
	NES: "|",
	NSW: "|",
	NE:  "|",
	NW:  "|",
	SW:  "|",
	ES:  "|",
	EW:  "-",
	NS:  "|",
}
View Source
var NoDividers = Dividers{}
View Source
var StarDividers = Dividers{
	ALL: "*",
	NES: "*",
	NSW: "*",
	NEW: "*",
	ESW: "*",
	NE:  "*",
	NW:  "*",
	SW:  "*",
	ES:  "*",
	EW:  "*",
	NS:  "*",
}
View Source
var UnicodeDividers = Dividers{
	ALL: "โ”ผ",
	NES: "โ”œ",
	NSW: "โ”ค",
	NEW: "โ”ด",
	ESW: "โ”ฌ",
	NE:  "โ””",
	NW:  "โ”˜",
	SW:  "โ”",
	ES:  "โ”Œ",
	EW:  "โ”€",
	NS:  "โ”‚",
}
View Source
var UnicodeRoundedDividers = Dividers{
	ALL: "โ”ผ",
	NES: "โ”œ",
	NSW: "โ”ค",
	NEW: "โ”ด",
	ESW: "โ”ฌ",
	NE:  "โ•ฐ",
	NW:  "โ•ฏ",
	SW:  "โ•ฎ",
	ES:  "โ•ญ",
	EW:  "โ”€",
	NS:  "โ”‚",
}

Functions ยถ

This section is empty.

Types ยถ

type Alignment ยถ

type Alignment uint8
const (
	AlignLeft Alignment = iota
	AlignRight
	AlignCenter
	AlignBottom
	AlignTop
)

type Borders ยถ

type Borders struct {
	Left   bool
	Top    bool
	Right  bool
	Bottom bool
}

Borders dictates whether to draw lines at the extreme edges of the table

type Dividers ยถ

type Dividers struct {
	ALL string
	NES string
	NSW string
	NEW string
	ESW string
	NE  string
	NW  string
	SW  string
	ES  string
	EW  string
	NS  string
}

type Style ยถ

type Style int
const (
	StyleNormal    Style = 0
	StyleBold      Style = 1
	StyleDim       Style = 2
	StyleItalic    Style = 3
	StyleUnderline Style = 4

	StyleBlack   Style = 30
	StyleRed     Style = 31
	StyleGreen   Style = 32
	StyleYellow  Style = 33
	StyleBlue    Style = 34
	StyleMagenta Style = 35
	StyleCyan    Style = 36
	StyleWhite   Style = 37

	StyleBrightBlack   Style = 90
	StyleBrightRed     Style = 91
	StyleBrightGreen   Style = 92
	StyleBrightYellow  Style = 93
	StyleBrightBlue    Style = 94
	StyleBrightMagenta Style = 95
	StyleBrightCyan    Style = 96
	StyleBrightWhite   Style = 97
)

type Table ยถ

type Table struct {
	// contains filtered or unexported fields
}

Table holds information required to render a table to the terminal

func New ยถ

func New(w io.Writer) *Table

New creates a new Table

func (*Table) AddFooters ยถ

func (t *Table) AddFooters(footers ...string)

AddFooters adds a row of footers to the table.

func (*Table) AddHeaders ยถ

func (t *Table) AddHeaders(headers ...string)

AddHeaders adds a row of headers to the table.

func (*Table) AddRow ยถ

func (t *Table) AddRow(cols ...string)

AddRow adds a row to the table. Each argument is a column value.

func (*Table) AddRows ยถ

func (t *Table) AddRows(rows ...[]string)

AddRows adds multiple rows to the table. Each argument is a row, i.e. a slice of column values.

func (*Table) LoadCSV ยถ

func (t *Table) LoadCSV(r io.Reader, hasHeaders bool) error

LoadCSV loads CSV data from a reader and adds it to the table. Existing rows/headers/footers are retained.

func (*Table) Render ยถ

func (t *Table) Render()

Render writes the table to the provider io.Writer

func (*Table) SetAlignment ยถ

func (t *Table) SetAlignment(columns ...Alignment)

SetAlignment sets the alignment of each column. Should be specified for each column in the supplied data. Default alignment for columns is AlignLeft

func (*Table) SetAutoMerge ยถ

func (t *Table) SetAutoMerge(enabled bool)

SetAutoMerge sets whether to merge cells vertically if their content is the same and non-empty

func (*Table) SetAutoMergeHeaders ยถ

func (t *Table) SetAutoMergeHeaders(enabled bool)

SetAutoMergeHeaders sets whether to merge header cells vertically if their content is the same and non-empty

func (*Table) SetAvailableWidth ยถ

func (t *Table) SetAvailableWidth(w int)

SetAvailableWidth sets the available width for the table (defaults to terminal width when stdout is used)

func (*Table) SetBorderBottom ยถ

func (t *Table) SetBorderBottom(enabled bool)

SetBorderBottom enables/disables the border line on the bottom edge of the table

func (*Table) SetBorderLeft ยถ

func (t *Table) SetBorderLeft(enabled bool)

SetBorderLeft enables/disables the border line on the left edge of the table

func (*Table) SetBorderRight ยถ

func (t *Table) SetBorderRight(enabled bool)

SetBorderRight enables/disables the border line on the right edge of the table

func (*Table) SetBorderTop ยถ

func (t *Table) SetBorderTop(enabled bool)

SetBorderTop enables/disables the border line on the top edge of the table

func (*Table) SetBorders ยถ

func (t *Table) SetBorders(enabled bool)

SetBorders enables/disables the border around the table

func (*Table) SetColSpans ยถ

func (t *Table) SetColSpans(rowIndex int, colSpans ...int)

SetColSpans sets a column span for each column in the given row.

func (*Table) SetColumnMaxWidth ยถ

func (t *Table) SetColumnMaxWidth(maxColumnWidth int)

SetColumnMaxWidth sets the max column width

func (*Table) SetDividers ยถ

func (t *Table) SetDividers(d Dividers)

SetDividers allows customisation of the characters used to draw the table. There are several built-in options, such as UnicodeRoundedDividers. Specifying divider values containing more than 1 rune will result in undefined behaviour.

func (*Table) SetFillWidth ยถ

func (t *Table) SetFillWidth(enabled bool)

SetFillWidth sets whether to fill the entire available width

func (*Table) SetFooterAlignment ยถ

func (t *Table) SetFooterAlignment(columns ...Alignment)

SetFooterAlignment sets the alignment of each footer. Should be specified for each footer in the supplied data. Default alignment for footers is AlignCenter

func (*Table) SetFooterColSpans ยถ

func (t *Table) SetFooterColSpans(rowIndex int, colSpans ...int)

SetFooterColSpans sets a column span for each column in the given footer row.

func (*Table) SetFooters ยถ

func (t *Table) SetFooters(footers ...string)

SetFooters set the footers used for the table.

func (*Table) SetHeaderAlignment ยถ

func (t *Table) SetHeaderAlignment(columns ...Alignment)

SetHeaderAlignment sets the alignment of each header. Should be specified for each header in the supplied data. Default alignment for headers is AlignCenter

func (*Table) SetHeaderColSpans ยถ

func (t *Table) SetHeaderColSpans(rowIndex int, colSpans ...int)

SetHeaderColSpans sets a column span for each column in the given header row.

func (*Table) SetHeaderStyle ยถ

func (t *Table) SetHeaderStyle(s Style)

SetHeaderStyle set the style used for headers

func (*Table) SetHeaderVerticalAlignment ยถ

func (t *Table) SetHeaderVerticalAlignment(a Alignment)

func (*Table) SetHeaders ยถ

func (t *Table) SetHeaders(headers ...string)

SetHeaders set the headers used for the table.

func (*Table) SetLineStyle ยถ

func (t *Table) SetLineStyle(s Style)

SetLineStyle sets the ANSI style of the lines used when drawing the table. e.g. StyleYellow

func (*Table) SetPadding ยถ

func (t *Table) SetPadding(padding int)

SetPadding sets the minimum number of spaces which must surround each column value (horizontally). For example, a padding of 3 would result in a column value such as " hello world " (3 spaces either side)

func (*Table) SetRowLines ยถ

func (t *Table) SetRowLines(enabled bool)

SetRowLines sets whether to render horizontal lines between rows

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL