Exemplo n.º 1
0
func Example() {
	// Create a table with some columns.
	lf := tablist.NewFormater(
		tablist.NewColRight(0, "column 0"),
		tablist.NewColLeft(0, "column 1"),
		tablist.NewColLeft(23, "column 2"),
	)

	// Add a few lines of data.
	for _, item := range []struct {
		c0, c1, c2 string
	}{
		{"content", "this is on the left", "also left"},
		{"aligned", "with an empty cell", "with fixed size"},
		{"on the right", "", "can truncate the content too large"},
	} {
		line := lf.AddLine()
		line.Set(0, item.c0) // You better use constants to refer to your column ID.
		line.Set(1, item.c1)
		line.Set(2, item.c2)
	}

	lf.AddSeparator()

	sepInfo := lf.AddLine()
	sepInfo.Set(1, "AddSeparator")
	sepInfo.Set(2, "separator visible above")

	// Disable the group color for the example test.
	tablist.GroupColor = ""
	lf.AddGroup(1, "AddGroup")

	lineInfo := lf.AddLine()
	lineInfo.Set(1, "AddLine")
	lineInfo.Set(2, "a basic line")

	emptyFilled := lf.AddEmptyFilled()
	emptyFilled.Set(1, "AddEmptyFilled")
	emptyFilled.Set(2, "fills empty cells")

	// Prints the result to console.
	lf.Print()

	// Output:
	// ┌column 0──────┬column 1─────────────┬column 2─────────────────┐
	// │      content │ this is on the left │ also left               │
	// │      aligned │ with an empty cell  │ with fixed size         │
	// │ on the right │                     │ can truncate the conten │
	// ├──────────────┼─────────────────────┼─────────────────────────┤
	// │              │ AddSeparator        │ separator visible above │
	// ├──────────────┼AddGroup─────────────┼─────────────────────────┤
	// │              │ AddLine             │ a basic line            │
	// │──────────────│ AddEmptyFilled      │ fills empty cells       │
	// └──────────────┴─────────────────────┴─────────────────────────┘
}
Exemplo n.º 2
0
func TestTableColor(t *testing.T) {
	tablist.GroupColor = color.FgRed
	// Create a table with some columns.
	lf := tablist.NewFormater(
		tablist.NewColRight(0, "column 0"),
	)
	lf.AddGroup(0, "group")

	assert.Equal(t, 1, lf.Count(), "Count")
	groupColor := color.FgRed + "group" + color.Reset
	output := `┌column ┐
├` + groupColor + `──┤
└───────┘`
	assert.Equal(t, output, lf.Sprint(), "Count")

}
Exemplo n.º 3
0
// Format applet packages using simple table formater.
//
func printConsole(list packages.AppletPackages) {
	lf := tablist.NewFormater(
		tablist.NewColRight(0, "Inst"),
		tablist.NewColLeft(0, "[ Applet ]"),
		tablist.NewColLeft(0, "Category"),
	)

	for _, pack := range list {
		line := lf.AddLine()
		if pack.Type == packages.TypeUser {
			line.Colored(0, color.FgGreen, " * ")
		}
		if pack.Type == packages.TypeInDev {
			line.Colored(0, color.FgYellow, " * ")
		}

		line.Set(1, pack.DisplayedName)
		cat, _ := packages.FormatCategory(pack.Category)
		line.Set(2, cat)
	}
	lf.Print()
}