all repos — mx @ 4ae2f6e2c20f22ebb6b3d478313dce9a89c870e6

work in progress MUA

commands/table.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
package commands

import (
	"os"

	"github.com/jedib0t/go-pretty/v6/table"
	"github.com/jedib0t/go-pretty/v6/text"

	"git.icyphox.sh/mx/term"
)

func GetTable() table.Writer {
	w, _, _ := term.GetSize()
	t := table.NewWriter()
	t.SetOutputMirror(os.Stdout)

	t.SetStyle(table.Style{
		Box: table.BoxStyle{
			BottomLeft:       " ",
			BottomRight:      " ",
			BottomSeparator:  " ",
			EmptySeparator:   text.RepeatAndTrim(" ", text.RuneCount(" ")),
			Left:             "",
			LeftSeparator:    " ",
			MiddleHorizontal: " ",
			MiddleSeparator:  " ",
			MiddleVertical:   " ",
			PaddingLeft:      " ",
			PaddingRight:     " ",
			PageSeparator:    "\n",
			Right:            " ",
			RightSeparator:   " ",
			TopLeft:          " ",
			TopRight:         " ",
			TopSeparator:     " ",
			UnfinishedRow:    "",
		},
	})
	t.SetColumnConfigs([]table.ColumnConfig{
		{Number: 3, WidthMax: 20, WidthMaxEnforcer: text.Trim},
	})
	t.SetAllowedRowLength(w)
	return t
}