Beispiel #1
0
func (lf *lineFeed) addTest(key *cftype.Key) {
	def, e := key.Storage().Default(key.Group, key.Name)
	if e != nil {
		println("default: ", e.Error())
		return
	}

	valStatus := key.ValueState(def)
	if !valStatus.IsChanged() {
		return
	}

	lf.countChanged++

	lf.valuePrint = func(key *cftype.Key, line tablist.Liner) {
		for i, st := range valStatus {
			curline := lf.testNewLine(line, i)
			switch {
			// case cftype.StateUnchanged:
			// 	curline.Set(RowOld, st.Old)

			case st.State == cftype.StateEdited && st.New != "":
				curline.Set(RowOld, st.New)

			case st.State == cftype.StateAdded:
				curline.Colored(RowOld, color.FgYellow, st.New)

			case st.State == cftype.StateEdited, st.State == cftype.StateRemoved:
				curline.Colored(RowOld, color.FgMagenta, "**EMPTY**")
			}
		}
	}

	lf.Add(key)
}
Beispiel #2
0
func (lf *lineFeed) valueDefault(key *cftype.Key, line tablist.Liner) {
	flag := false

	def, e := key.Storage().Default(key.Group, key.Name)
	if e != nil {
		println("default: ", e.Error())
	}

	valStatus := key.ValueState(def)

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

		case cftype.StateBothEmpty:
			line.Set(RowOld, "**EMPTY**")

		case cftype.StateUnchanged:
			curline.Set(RowOld, st.Old)

		case cftype.StateEdited:
			curline.Set(RowOld, st.Old)
			if st.New == "" {
				curline.Colored(RowNew, color.FgMagenta, "**EMPTY**")
			} else {
				curline.Colored(RowNew, color.FgGreen, st.New)
			}
			flag = true

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

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

	if flag {
		lf.countChanged++
	}
}
Beispiel #3
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++
	}
}