From f9dda9a86b6096e5e93c18656dba830e8c9c0eb9 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Tue, 17 Aug 2021 20:48:49 +0900 Subject: [PATCH] Fix diff bug --- go.mod | 5 ++--- go.sum | 4 +++- snapshot.go | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 896723c..fef63a8 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/sachaos/viddy go 1.16 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/fatih/color v1.12.0 // indirect + github.com/fatih/color v1.12.0 github.com/gdamore/tcell/v2 v2.3.3 github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2 - github.com/sergi/go-diff v1.2.0 // indirect + github.com/sergi/go-diff v1.2.0 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index 1c403ba..f69878a 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,10 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.3.3 h1:RKoI6OcqYrr/Do8yHZklecdGzDTJH9ACKdfECbRdw3M= github.com/gdamore/tcell/v2 v2.3.3/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -44,8 +46,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/snapshot.go b/snapshot.go index afcf5d6..8eba60e 100644 --- a/snapshot.go +++ b/snapshot.go @@ -109,12 +109,21 @@ func (s *Snapshot) run(finishedQueue chan<- int64) error { return nil } -func (s *Snapshot) render(w io.Writer, diff bool, query string) error { +func (s *Snapshot) render(w io.Writer, isShowDiff bool, query string) error { var err error var src string - if diff && s.diffPrepared { - src = DiffPrettyText(s.diff) + if isShowDiff { + if s.diffPrepared { + src = DiffPrettyText(s.diff) + } else { + err := s.compareFromBefore() + if err != nil { + src = string(s.result) + } else { + src = DiffPrettyText(s.diff) + } + } } else { src = string(s.result) }