コード例 #1
0
ファイル: cfprint.go プロジェクト: sqp/godock
// Default prints the configuration compared to its default values.
//
func Default(build cftype.Builder, showAll bool) {
	cols := []tablist.ColInfo{
		tablist.NewColLeft(0, "Type"),
		tablist.NewColLeft(0, "Name"),
	}

	if showAll {
		cols = append(cols,
			tablist.NewColLeft(0, "Default"),
		)
	}
	cols = append(cols,
		tablist.NewColLeft(0, "Current"),
	)

	lf := &lineFeed{
		TableFormater: *tablist.NewFormater(cols...),
	}
	if showAll {
		lf.valuePrint = lf.valueDefault
		build.KeyWalk(lf.Add)
	} else {
		build.KeyWalk(lf.addTest)
	}

	lf.Print()

	if lf.countChanged > 0 {
		build.Log().Info("changed", lf.countChanged, "/", lf.countChangeable)
	} else {
		build.Log().Info("nothing changed")
	}
}
コード例 #2
0
ファイル: tablist_test.go プロジェクト: sqp/godock
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       │
	// └──────────────┴─────────────────────┴─────────────────────────┘
}
コード例 #3
0
ファイル: color_test.go プロジェクト: sqp/godock
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")

}
コード例 #4
0
ファイル: cfprint.go プロジェクト: sqp/godock
// Updated prints the configuration compared to its storage values.
//
func Updated(build cftype.Builder) {
	// build.Log().DEV("save to virtual")
	lf := &lineFeed{
		TableFormater: *tablist.NewFormater(
			tablist.NewColLeft(0, "Type"),
			tablist.NewColLeft(0, "Name"),
			tablist.NewColLeft(0, "Old value"),
			tablist.NewColLeft(0, "New value"),
		),
	}
	lf.valuePrint = lf.valueUpdated

	build.KeyWalk(lf.Add)
	lf.Print()

	if lf.countChanged > 0 {
		build.Log().Info("changed", lf.countChanged, "/", lf.countChangeable)
	} else {
		build.Log().Info("nothing changed")
	}
}
コード例 #5
0
ファイル: external.go プロジェクト: sqp/godock
// 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()
}