Skip to content

Commit

Permalink
feat: added color diff output that works with global color flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Osterbind committed Feb 28, 2018
1 parent 7f38363 commit d46afac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ either by name or by their hash`,
case "delta":
displayFormat = "delta"
case "detail":
displayFormat = "plusMinusColor"
displayFormat = "plusMinus"
}
}
result, err := datasetDiffer.MapDiffsToString(diffs, displayFormat)
ExitIfErr(err)
fmt.Println(result)

printDiffs(result)
},
}

Expand Down
36 changes: 36 additions & 0 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,39 @@ func inputText(message, defaultText string) string {

return input
}

/*
white := color.New(color.FgWhite).SprintFunc()
cyan := color.New(color.FgCyan).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
fmt.Printf("%s:\t%s\n\t%s\n", cyan(i), white(r.Dataset.Transform.Data), blue(r.Path))
*/
func printDiffs(diffText string) {
green := color.New(color.FgGreen).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
lines := strings.Split(diffText, "\n")
for _, line := range lines {
if len(line) >= 3 {
if line[:2] == "+ " || line[:2] == "++" {
fmt.Printf("%s\n", green(line))
} else if line[:2] == "- " || line[:2] == "--" {
fmt.Printf("%s\n", red(line))
} else {
fmt.Printf("%s\n", line)
}
} else {
fmt.Printf("%s\n", line)
}
}
// output := ""
// for _, line := range lines {
// if len(line) >= 3 && (line[:2] == "+ " || line[:2] == "++") {
// output += fmt.Sprintf("🎾%s\n", green(line))
// } else if len(line) >= 3 && (line[:2] == "- " || line[:2] == "--") {
// output += fmt.Sprintf("🏓%s\n", red(line))
// } else {
// output += fmt.Sprintf("%s\n", line)
// }
// }
// fmt.Printf("%s", output)
}

0 comments on commit d46afac

Please sign in to comment.