Example #1
0
func showCompare(mark changeMark, c gompatible.Change, show func(changeMark, string), doDiff bool) {
	if doDiff == false {
		show(mark, c.ShowBefore())
		show(markConfer, c.ShowAfter())
		return
	}

	d, err := diff([]byte(c.ShowBefore()), []byte(c.ShowAfter()))
	dieIf(err)

	ct.ChangeColor(mark.color, false, ct.None, false)
	fmt.Print(mark.mark)
	ct.ResetColor()

	fmt.Println(typesObjectString(c.TypesObject()))

	lines := strings.Split(string(d), "\n")
	inHeader := true
	for _, line := range lines {
		if inHeader {
			if rxDiffThunkStart.MatchString(line) {
				inHeader = false
			} else {
				continue
			}
		}
		fmt.Println("  " + line)
	}
}
Example #2
0
func printChange(c gompatible.Change, doDiff bool) {
	show := func(mark changeMark, s string) {
		lines := strings.Split(s, "\n")
		for i := range lines {
			if i == 0 {
				ct.ChangeColor(mark.color, false, ct.None, false)
				fmt.Print(string(mark.mark[:]))
				ct.ResetColor()
				fmt.Println(lines[i])
			} else {
				fmt.Println(" ", lines[i])
			}
		}
	}

	switch c.Kind() {
	case gompatible.ChangeAdded:
		show(markAdded, c.ShowAfter())
	case gompatible.ChangeRemoved:
		show(markRemoved, c.ShowBefore())
	case gompatible.ChangeUnchanged:
		show(markUnchanged, c.ShowBefore())
	case gompatible.ChangeCompatible:
		showCompare(markCompatible, c, show, doDiff)
	case gompatible.ChangeBreaking:
		showCompare(markBreaking, c, show, doDiff)
	}
}