summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2021-07-27 15:00:37 +0200
committermjarkk <mkopenga@gmail.com>2021-07-30 15:14:46 +0200
commit79848087bccd5c87af1dbb44a39753aad1346f8b (patch)
tree07e4b6eb4b7ed5fdcbde8d697a214b647ddd0536 /pkg/commands
parenta3b820fb5f20f4a24028ecbf285d54bbaa7b6974 (diff)
Switch to github.com/gookit/color for terminal colors
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/loading_commits.go5
-rw-r--r--pkg/commands/patch/patch_parser.go37
2 files changed, 17 insertions, 25 deletions
diff --git a/pkg/commands/loading_commits.go b/pkg/commands/loading_commits.go
index bf7e4cf56..28e9c5199 100644
--- a/pkg/commands/loading_commits.go
+++ b/pkg/commands/loading_commits.go
@@ -10,9 +10,9 @@ import (
"strconv"
"strings"
- "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/sirupsen/logrus"
)
@@ -165,8 +165,7 @@ func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Commit
if rebaseMode != "" {
currentCommit := commits[len(rebasingCommits)]
- blue := color.New(color.FgYellow)
- youAreHere := blue.Sprintf("<-- %s ---", c.Tr.YouAreHere)
+ youAreHere := style.FgYellow.Sprintf("<-- %s ---", c.Tr.YouAreHere)
currentCommit.Name = fmt.Sprintf("%s %s", youAreHere, currentCommit.Name)
}
diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go
index a5a94964f..66e100ece 100644
--- a/pkg/commands/patch/patch_parser.go
+++ b/pkg/commands/patch/patch_parser.go
@@ -4,7 +4,7 @@ import (
"regexp"
"strings"
- "github.com/fatih/color"
+ "github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
@@ -95,45 +95,38 @@ func (l *PatchLine) render(selected bool, included bool) string {
if l.Kind == HUNK_HEADER {
re := regexp.MustCompile("(@@.*?@@)(.*)")
match := re.FindStringSubmatch(content)
- return coloredString(color.FgCyan, match[1], selected, included) + coloredString(theme.DefaultTextColor, match[2], selected, false)
+ return coloredString(style.FgCyan, match[1], selected, included) + coloredString(theme.DefaultTextColor, match[2], selected, false)
}
- var colorAttr color.Attribute
+ colorAttr := theme.DefaultTextColor
switch l.Kind {
case PATCH_HEADER:
- colorAttr = color.Bold
+ colorAttr = colorAttr.SetBold(true)
case ADDITION:
- colorAttr = color.FgGreen
+ colorAttr = colorAttr.SetColor(style.FgGreen)
case DELETION:
- colorAttr = color.FgRed
+ colorAttr = colorAttr.SetColor(style.FgRed)
case COMMIT_SHA:
- colorAttr = color.FgYellow
- default:
- colorAttr = theme.DefaultTextColor
+ colorAttr = colorAttr.SetColor(style.FgYellow)
}
return coloredString(colorAttr, content, selected, included)
}
-func coloredString(colorAttr color.Attribute, str string, selected bool, included bool) string {
- var cl *color.Color
- attributes := []color.Attribute{colorAttr}
+func coloredString(colorAttr style.TextStyle, str string, selected bool, included bool) string {
if selected {
- attributes = append(attributes, theme.SelectedRangeBgColor)
- }
- cl = color.New(attributes...)
- var clIncluded *color.Color
- if included {
- clIncluded = color.New(append(attributes, color.BgGreen)...)
- } else {
- clIncluded = color.New(attributes...)
+ colorAttr = colorAttr.SetColor(theme.SelectedRangeBgColor)
}
if len(str) < 2 {
- return utils.ColoredStringDirect(str, clIncluded)
+ return colorAttr.Sprint(str)
}
- return utils.ColoredStringDirect(str[:1], clIncluded) + utils.ColoredStringDirect(str[1:], cl)
+ res := colorAttr.Sprint(str[:1])
+ if included {
+ return res + colorAttr.SetColor(style.BgGreen).Sprint(str[1:])
+ }
+ return res + colorAttr.Sprint(str[1:])
}
func parsePatch(patch string) ([]int, []int, []*PatchLine) {