Ejemplo n.º 1
0
// Add adds a key to the printer.
//
func (lf *lineFeed) Add(key *cftype.Key) {
	if key.Group != lf.lastGroup {
		lf.AddGroup(RowName, key.Group)
		lf.lastGroup = key.Group
		lf.hasFrame = false
	}

	var line tablist.Liner
	var title string
	switch {
	case key.IsType(cftype.KeyFrame, cftype.KeyExpander):
		line = lf.AddEmptyFilled()
		lf.hasFrame = true
		line.Set(RowType, key.Type.String())
		if len(key.AuthorizedValues) == 0 {
			title = "[*FRAME NO TITLE*]"
		} else {
			title = key.AuthorizedValues[0]
		}

	case key.IsType(cftype.KeySeparator):
		line = lf.AddEmptyFilled()
		line.Set(RowType, key.Type.String())
		title = lf.indent() + "---------"

	case key.IsType(cftype.KeyTextLabel, cftype.KeyLaunchCmdSimple):
		line = lf.AddEmptyFilled()
		line.Set(RowType, key.Type.String())
		title = lf.indent() + key.Name

	default:
		line = lf.AddLine()
		lf.valuePrint(key, line)
		line.Colored(RowType, color.FgGreen, key.Type.String())
		title = lf.indent() + key.Name
		lf.countChangeable++
	}

	line.Set(RowName, title)
}
Ejemplo n.º 2
0
func (lf *lineFeed) valueUpdated(key *cftype.Key, line tablist.Liner) {
	flag := false
	older := key.Storage().Valuer(key.Group, key.Name)
	valStatus := key.ValueState(older)

	for i, st := range valStatus {
		curline := lf.testNewLine(line, i)
		switch st.State {

		case cftype.StateBothEmpty:
			line.Colored(RowOld, color.FgMagenta, "**EMPTY**")
			line.Colored(RowNew, color.BgRed, "  ==  ")

		case cftype.StateUnchanged:
			curline.Set(RowOld, st.Old)
			curline.Colored(RowNew, color.BgRed, "  ==  ")

		case cftype.StateEdited:
			curline.Set(RowOld, st.Old)
			st.New = ternary.String(st.New == "", "**EMPTY**", st.New)
			curline.Colored(RowNew, color.FgGreen, st.New)
			flag = true

		case cftype.StateAdded:
			curline.Set(RowOld, "**EMPTY**")
			curline.Colored(RowNew, color.FgGreen, st.New)
			flag = true

		case cftype.StateRemoved:
			curline.Set(RowOld, st.Old)
			curline.Colored(RowNew, color.FgGreen, "**EMPTY**")
			flag = true
		}
	}

	if flag {
		lf.countChanged++
	}
}