File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 11package carapace
22
33import (
4+ "fmt"
5+
46 "github.com/carapace-sh/carapace/internal/common"
57 "github.com/carapace-sh/carapace/pkg/style"
68)
@@ -42,3 +44,27 @@ func Diff(original, new Action) Action {
4244 return mergedBatch .ToA ()
4345 })
4446}
47+
48+ // TODO experimental - needs different signature
49+ // TODO return patch format
50+ func DiffPatch (original , new Action , c Context ) []string {
51+ diff := Diff (original , new ).Invoke (c )
52+ patch := make ([]string , 0 )
53+ for _ , v := range diff .action .rawValues {
54+ s := v .Value
55+ if v .Description != "" {
56+ s += fmt .Sprintf (" (%v)" , v .Description )
57+ }
58+
59+ switch v .Style {
60+ case style .Red :
61+ s = "- " + s
62+ case style .Green :
63+ s = "+ " + s
64+ default :
65+ s = " " + s
66+ }
67+ patch = append (patch , s )
68+ }
69+ return patch
70+ }
You can’t perform that action at this time.
0 commit comments