Skip to content

Commit 56b69a3

Browse files
cwrauHeavyWombat
authored andcommitted
feat: allow disabling indent lines
This makes it possible to copy the diffed lines without weird characters in them
1 parent 4203f45 commit 56b69a3

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

internal/cmd/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ func writeReport(cmd *cobra.Command, report dyff.Report) error {
217217
reportWriter = &dyff.HumanReport{
218218
Report: report,
219219
Indent: 2,
220+
UseIndentLines: true,
220221
DoNotInspectCerts: reportOptions.doNotInspectCerts,
221222
NoTableStyle: reportOptions.noTableStyle,
222223
OmitHeader: reportOptions.omitHeader,
@@ -234,6 +235,7 @@ func writeReport(cmd *cobra.Command, report dyff.Report) error {
234235
HumanReport: dyff.HumanReport{
235236
Report: report,
236237
Indent: 0,
238+
UseIndentLines: true,
237239
DoNotInspectCerts: reportOptions.doNotInspectCerts,
238240
NoTableStyle: true,
239241
OmitHeader: true,
@@ -252,6 +254,7 @@ func writeReport(cmd *cobra.Command, report dyff.Report) error {
252254
HumanReport: dyff.HumanReport{
253255
Report: report,
254256
Indent: 0,
257+
UseIndentLines: true,
255258
DoNotInspectCerts: reportOptions.doNotInspectCerts,
256259
NoTableStyle: true,
257260
OmitHeader: true,
@@ -270,6 +273,7 @@ func writeReport(cmd *cobra.Command, report dyff.Report) error {
270273
HumanReport: dyff.HumanReport{
271274
Report: report,
272275
Indent: 0,
276+
UseIndentLines: true,
273277
DoNotInspectCerts: reportOptions.doNotInspectCerts,
274278
NoTableStyle: true,
275279
OmitHeader: true,

pkg/dyff/core_suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func compareAgainstExpectedHuman(fromPath string, toPath string, expectedPath st
135135
reportWriter := &dyff.HumanReport{
136136
Report: report,
137137
Indent: 2,
138+
UseIndentLines: true,
138139
DoNotInspectCerts: false,
139140
NoTableStyle: false,
140141
OmitHeader: true,
@@ -171,6 +172,7 @@ func compareAgainstExpectedDiffSyntax(fromPath string, toPath string, expectedPa
171172
HumanReport: dyff.HumanReport{
172173
Report: report,
173174
Indent: 0,
175+
UseIndentLines: true,
174176
DoNotInspectCerts: false,
175177
NoTableStyle: true,
176178
OmitHeader: true,
@@ -275,6 +277,7 @@ func humanDiff(diff dyff.Diff) string {
275277
reporter := dyff.HumanReport{
276278
Report: dyff.Report{Diffs: []dyff.Diff{diff}},
277279
Indent: 2,
280+
UseIndentLines: true,
278281
DoNotInspectCerts: false,
279282
NoTableStyle: false,
280283
OmitHeader: true,
@@ -296,6 +299,7 @@ func diffSyntaxDiff(diff dyff.Diff) string {
296299
HumanReport: dyff.HumanReport{
297300
Report: dyff.Report{Diffs: []dyff.Diff{diff}},
298301
Indent: 0,
302+
UseIndentLines: true,
299303
DoNotInspectCerts: false,
300304
NoTableStyle: true,
301305
OmitHeader: true,

pkg/dyff/output.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"github.com/lucasb-eyer/go-colorful"
2727
)
2828

29-
func yamlStringInRedishColors(input interface{}) (string, error) {
30-
return neat.NewOutputProcessor(true, true, &map[string]colorful.Color{
29+
func yamlStringInRedishColors(input interface{}, useIndentLines bool) (string, error) {
30+
return neat.NewOutputProcessor(useIndentLines, true, &map[string]colorful.Color{
3131
"keyColor": bunt.FireBrick,
3232
"indentLineColor": {R: 0.2, G: 0, B: 0},
3333
"scalarDefaultColor": bunt.LightCoral,
@@ -41,8 +41,8 @@ func yamlStringInRedishColors(input interface{}) (string, error) {
4141
}).ToYAML(input)
4242
}
4343

44-
func yamlStringInGreenishColors(input interface{}) (string, error) {
45-
return neat.NewOutputProcessor(true, true, &map[string]colorful.Color{
44+
func yamlStringInGreenishColors(input interface{}, useIndentLines bool) (string, error) {
45+
return neat.NewOutputProcessor(useIndentLines, true, &map[string]colorful.Color{
4646
"keyColor": bunt.Green,
4747
"indentLineColor": {R: 0, G: 0.2, B: 0},
4848
"scalarDefaultColor": bunt.LimeGreen,

pkg/dyff/output_human.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type stringWriter interface {
5353
type HumanReport struct {
5454
Report
5555
Indent int
56+
UseIndentLines bool
5657
MinorChangeThreshold float64
5758
MultilineContextLines int
5859
NoTableStyle bool
@@ -184,7 +185,7 @@ func (report *HumanReport) generateHumanDetailOutputAddition(detail Detail) (str
184185
}
185186

186187
ytbx.RestructureObject(detail.To)
187-
yamlOutput, err := yamlStringInGreenishColors(detail.To)
188+
yamlOutput, err := yamlStringInGreenishColors(detail.To, report.UseIndentLines)
188189
if err != nil {
189190
return "", err
190191
}
@@ -214,7 +215,7 @@ func (report *HumanReport) generateHumanDetailOutputRemoval(detail Detail) (stri
214215
}
215216

216217
ytbx.RestructureObject(detail.From)
217-
yamlOutput, err := yamlStringInRedishColors(detail.From)
218+
yamlOutput, err := yamlStringInRedishColors(detail.From, report.UseIndentLines)
218219
if err != nil {
219220
return "", err
220221
}

0 commit comments

Comments
 (0)