diff options
Diffstat (limited to 'pkg/gui/textstyle.go')
| -rw-r--r-- | pkg/gui/textstyle.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/gui/textstyle.go b/pkg/gui/textstyle.go index 50bc945..33f172d 100644 --- a/pkg/gui/textstyle.go +++ b/pkg/gui/textstyle.go @@ -2,6 +2,7 @@ package gui import ( "regexp" + "strings" "github.com/fatih/color" "github.com/isacikgoz/gitbatch/pkg/git" @@ -118,6 +119,30 @@ func adjustTextLength(text string, maxLength int) (adjusted string) { return text } +// colorize the plain diff text collected from system output +// the style is near to original diff command +func colorizeDiff(original string) (colorized []string) { + colorized = strings.Split(original, "\n") + re := regexp.MustCompile(`@@ .+ @@`) + for i, line := range colorized { + if len(line) > 0 { + if line[0] == '-' { + colorized[i] = red.Sprint(line) + } else if line[0] == '+' { + colorized[i] = green.Sprint(line) + } else if re.MatchString(line) { + s := re.FindString(line) + colorized[i] = cyan.Sprint(s) + line[len(s):] + } else { + continue + } + } else { + continue + } + } + return colorized +} + // the remote link can be too verbose sometimes, so it is good to trim it func trimRemoteURL(url string) (urltype string, shorturl string) { // lets trim the unnecessary .git extension of the url |
