summaryrefslogtreecommitdiffstats
path: root/pkg/gui/presentation
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/presentation')
-rw-r--r--pkg/gui/presentation/branches.go48
-rw-r--r--pkg/gui/presentation/commit_files.go35
-rw-r--r--pkg/gui/presentation/commits.go2
-rw-r--r--pkg/gui/presentation/files.go36
-rw-r--r--pkg/gui/presentation/remote_branches.go23
-rw-r--r--pkg/gui/presentation/remotes.go20
-rw-r--r--pkg/gui/presentation/stash_entries.go20
-rw-r--r--pkg/gui/presentation/tags.go20
8 files changed, 203 insertions, 1 deletions
diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go
new file mode 100644
index 000000000..3b918116b
--- /dev/null
+++ b/pkg/gui/presentation/branches.go
@@ -0,0 +1,48 @@
+package presentation
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/fatih/color"
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/theme"
+ "github.com/jesseduffield/lazygit/pkg/utils"
+)
+
+func GetBranchListDisplayStrings(branches []*commands.Branch, isFocused bool, selectedLine int) [][]string {
+ lines := make([][]string, len(branches))
+
+ for i := range branches {
+ showUpstreamDifferences := isFocused && i == selectedLine
+ lines[i] = getBranchDisplayStrings(branches[i], showUpstreamDifferences)
+ }
+
+ return lines
+}
+
+// getBranchDisplayStrings returns the display string of branch
+func getBranchDisplayStrings(b *commands.Branch, showUpstreamDifferences bool) []string {
+ displayName := utils.ColoredString(b.Name, GetBranchColor(b.Name))
+ if showUpstreamDifferences && b.Pushables != "" && b.Pullables != "" {
+ displayName = fmt.Sprintf("%s ā†‘%sā†“%s", displayName, b.Pushables, b.Pullables)
+ }
+
+ return []string{b.Recency, displayName}
+}
+
+// GetBranchColor branch color
+func GetBranchColor(name string) color.Attribute {
+ branchType := strings.Split(name, "/")[0]
+
+ switch branchType {
+ case "feature":
+ return color.FgGreen
+ case "bugfix":
+ return color.FgYellow
+ case "hotfix":
+ return color.FgRed
+ default:
+ return theme.DefaultTextColor
+ }
+}
diff --git a/pkg/gui/presentation/commit_files.go b/pkg/gui/presentation/commit_files.go
new file mode 100644
index 000000000..4ea0f85db
--- /dev/null
+++ b/pkg/gui/presentation/commit_files.go
@@ -0,0 +1,35 @@
+package presentation
+
+import (
+ "github.com/fatih/color"
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/theme"
+)
+
+func GetCommitFileListDisplayStrings(branches []*commands.CommitFile) [][]string {
+ lines := make([][]string, len(branches))
+
+ for i := range branches {
+ lines[i] = getCommitFileDisplayStrings(branches[i])
+ }
+
+ return lines
+}
+
+// getCommitFileDisplayStrings returns the display string of branch
+func getCommitFileDisplayStrings(f *commands.CommitFile) []string {
+ yellow := color.New(color.FgYellow)
+ green := color.New(color.FgGreen)
+ defaultColor := color.New(theme.DefaultTextColor)
+
+ var colour *color.Color
+ switch f.Status {
+ case commands.UNSELECTED:
+ colour = defaultColor
+ case commands.WHOLE:
+ colour = green
+ case commands.PART:
+ colour = yellow
+ }
+ return []string{colour.Sprint(f.DisplayString)}
+}
diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go
index 04dbb0780..740abab78 100644
--- a/pkg/gui/presentation/commits.go
+++ b/pkg/gui/presentation/commits.go
@@ -67,7 +67,7 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit) []string {
secondColumnString := blue.Sprint(truncatedDate)
if c.Action != "" {
secondColumnString = cyan.Sprint(c.Action)
- } else if len(c.Tags) > 0 {
+ } else if c.ExtraInfo != "" {
tagColor := color.New(color.FgMagenta, color.Bold)
tagString = utils.ColoredStringDirect(c.ExtraInfo, tagColor) + " "
}
diff --git a/pkg/gui/presentation/files.go b/pkg/gui/presentation/files.go
new file mode 100644
index 000000000..589e8aecc
--- /dev/null
+++ b/pkg/gui/presentation/files.go
@@ -0,0 +1,36 @@
+package presentation
+
+import (
+ "github.com/fatih/color"
+ "github.com/jesseduffield/lazygit/pkg/commands"
+)
+
+func GetFileListDisplayStrings(files []*commands.File) [][]string {
+ lines := make([][]string, len(files))
+
+ for i := range files {
+ lines[i] = getFileDisplayStrings(files[i])
+ }
+
+ return lines
+}
+
+// getFileDisplayStrings returns the display string of branch
+func getFileDisplayStrings(f *commands.File) []string {
+ // potentially inefficient to be instantiating these color
+ // objects with each render
+ red := color.New(color.FgRed)
+ green := color.New(color.FgGreen)
+ if !f.Tracked && !f.HasStagedChanges {
+ return []string{red.Sprint(f.DisplayString)}
+ }
+
+ output := green.Sprint(f.DisplayString[0:1])
+ output += red.Sprint(f.DisplayString[1:3])
+ if f.HasUnstagedChanges {
+ output += red.Sprint(f.Name)
+ } else {
+ output += green.Sprint(f.Name)
+ }
+ return []string{output}
+}
diff --git a/pkg/gui/presentation/remote_branches.go b/pkg/gui/presentation/remote_branches.go
new file mode 100644
index 000000000..d3094c8cb
--- /dev/null
+++ b/pkg/gui/presentation/remote_branches.go
@@ -0,0 +1,23 @@
+package presentation
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/utils"
+)
+
+func GetRemoteBranchListDisplayStrings(branches []*commands.RemoteBranch) [][]string {
+ lines := make([][]string, len(branches))
+
+ for i := range branches {
+ lines[i] = getRemoteBranchDisplayStrings(branches[i])
+ }
+
+ return lines
+}
+
+// getRemoteBranchDisplayStrings returns the display string of branch
+func getRemoteBranchDisplayStrings(b *commands.RemoteBranch) []string {
+ displayName := utils.ColoredString(b.Name, GetBranchColor(b.Name))
+
+ return []string{displayName}
+}
diff --git a/pkg/gui/presentation/remotes.go b/pkg/gui/presentation/remotes.go
new file mode 100644
index 000000000..24fcd0b97
--- /dev/null
+++ b/pkg/gui/presentation/remotes.go
@@ -0,0 +1,20 @@
+package presentation
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+)
+
+func GetRemoteListDisplayStrings(remotes []*commands.Remote) [][]string {
+ lines := make([][]string, len(remotes))
+
+ for i := range remotes {
+ lines[i] = getRemoteDisplayStrings(remotes[i])
+ }
+
+ return lines
+}
+
+// getRemoteDisplayStrings returns the display string of branch
+func getRemoteDisplayStrings(r *commands.Remote) []string {
+ return []string{r.Name}
+}
diff --git a/pkg/gui/presentation/stash_entries.go b/pkg/gui/presentation/stash_entries.go
new file mode 100644
index 000000000..8598b5e5f
--- /dev/null
+++ b/pkg/gui/presentation/stash_entries.go
@@ -0,0 +1,20 @@
+package presentation
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+)
+
+func GetStashEntryListDisplayStrings(stashEntries []*commands.StashEntry) [][]string {
+ lines := make([][]string, len(stashEntries))
+
+ for i := range stashEntries {
+ lines[i] = getStashEntryDisplayStrings(stashEntries[i])
+ }
+
+ return lines
+}
+
+// getStashEntryDisplayStrings returns the display string of branch
+func getStashEntryDisplayStrings(s *commands.StashEntry) []string {
+ return []string{s.DisplayString}
+}
diff --git a/pkg/gui/presentation/tags.go b/pkg/gui/presentation/tags.go
new file mode 100644
index 000000000..13f2b8b59
--- /dev/null
+++ b/pkg/gui/presentation/tags.go
@@ -0,0 +1,20 @@
+package presentation
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+)
+
+func GetTagListDisplayStrings(tags []*commands.Tag) [][]string {
+ lines := make([][]string, len(tags))
+
+ for i := range tags {
+ lines[i] = getTagDisplayStrings(tags[i])
+ }
+
+ return lines
+}
+
+// getTagDisplayStrings returns the display string of branch
+func getTagDisplayStrings(t *commands.Tag) []string {
+ return []string{t.Name}
+}