@@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"fmt"
22
22
"io"
23
+ "os"
23
24
"runtime"
24
25
"strings"
25
26
)
@@ -29,6 +30,8 @@ const (
29
30
green = "\033 [32m"
30
31
)
31
32
33
+ var colorizeLog = true
34
+
32
35
func min (a , b int ) int {
33
36
if a < b {
34
37
return a
@@ -205,12 +208,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
205
208
// If IsJunk is not defined:
206
209
//
207
210
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
208
- // alo <= i <= i+k <= ahi
209
- // blo <= j <= j+k <= bhi
211
+ //
212
+ // alo <= i <= i+k <= ahi
213
+ // blo <= j <= j+k <= bhi
214
+ //
210
215
// and for all (i',j',k') meeting those conditions,
211
- // k >= k'
212
- // i <= i'
213
- // and if i == i', j <= j'
216
+ //
217
+ // k >= k'
218
+ // i <= i'
219
+ // and if i == i', j <= j'
214
220
//
215
221
// In other words, of all maximal matching blocks, return one that
216
222
// starts earliest in a, and of all those maximal matching blocks that
@@ -563,6 +569,7 @@ type UnifiedDiff struct {
563
569
// 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
564
570
// The modification times are normally expressed in the ISO 8601 format.
565
571
func WriteUnifiedDiff (writer io.Writer , diff UnifiedDiff ) error {
572
+ SetColorizeLogs ()
566
573
buf := bufio .NewWriter (writer )
567
574
defer buf .Flush ()
568
575
wf := func (format string , args ... interface {}) error {
@@ -638,7 +645,7 @@ func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
638
645
}
639
646
640
647
func colorize (color , message string ) string {
641
- if runtime .GOOS == "windows" {
648
+ if runtime .GOOS == "windows" || ! colorizeLog {
642
649
return message
643
650
}
644
651
return color + message + "\033 [0m"
@@ -783,3 +790,12 @@ func SplitLines(s string) []string {
783
790
lines [len (lines )- 1 ] += "\n "
784
791
return lines
785
792
}
793
+
794
+ // Remove colorizing from the log if env variable COLORIZE_LOGS=false
795
+ func SetColorizeLogs () {
796
+ colorize := os .Getenv ("COLORIZE_LOGS" )
797
+
798
+ if colorize == "false" {
799
+ colorizeLog = false
800
+ }
801
+ }
0 commit comments