6 "github.com/aymanbagabas/go-udiff"
7 "github.com/charmbracelet/crush/internal/config"
10// GenerateDiff creates a unified diff from two file contents
11func GenerateDiff(beforeContent, afterContent, fileName string) (string, int, int) {
12 // remove the cwd prefix and ensure consistent path format
13 // this prevents issues with absolute paths in different environments
14 cwd := config.WorkingDirectory()
15 fileName = strings.TrimPrefix(fileName, cwd)
16 fileName = strings.TrimPrefix(fileName, "/")
19 unified = udiff.Unified("a/"+fileName, "b/"+fileName, beforeContent, afterContent)
24 lines := strings.SplitSeq(unified, "\n")
25 for line := range lines {
26 if strings.HasPrefix(line, "+") && !strings.HasPrefix(line, "+++") {
28 } else if strings.HasPrefix(line, "-") && !strings.HasPrefix(line, "---") {
33 return unified, additions, removals
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list