1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

feat(gui): show remote icons

This commit is contained in:
Ryooooooga
2022-04-23 11:42:24 +09:00
parent 11d0e7e17d
commit f972d6ae68
2 changed files with 40 additions and 6 deletions

View File

@ -1,14 +1,31 @@
package icons
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
const BRANCH_ICON = "\ufb2b" // שׂ
const DETACHED_HEAD_ICON = "\ue729" //
const TAG_ICON = "\uf02b" //
const COMMIT_ICON = "\ufc16" //
const MERGE_COMMIT_ICON = "\ufb2c" //
const (
BRANCH_ICON = "\ufb2b" //
DETACHED_HEAD_ICON = "\ue729" //
TAG_ICON = "\uf02b" //
COMMIT_ICON = "\ufc16" //
MERGE_COMMIT_ICON = "\ufb2c" // שּׁ
DEFAULT_REMOTE_ICON = "\uf7a1" // 
)
type remoteIcon struct {
domain string
icon string
}
var remoteIcons = []remoteIcon{
{domain: "github.com", icon: "\ue709"}, // 
{domain: "bitbucket.org", icon: "\ue703"}, // 
{domain: "gitlab.com", icon: "\uf296"}, // 
{domain: "dev.azure.com", icon: "\ufd03"}, // ﴃ
}
func IconForBranch(branch *models.Branch) string {
if branch.DisplayName != "" {
@ -31,3 +48,14 @@ func IconForCommit(commit *models.Commit) string {
}
return COMMIT_ICON
}
func IconForRemote(remote *models.Remote) string {
for _, r := range remoteIcons {
for _, url := range remote.Urls {
if strings.Contains(url, r.domain) {
return r.icon
}
}
}
return DEFAULT_REMOTE_ICON
}

View File

@ -3,6 +3,7 @@ package presentation
import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme"
)
@ -23,5 +24,10 @@ func getRemoteDisplayStrings(r *models.Remote, diffed bool) []string {
textStyle = theme.DiffTerminalColor
}
return []string{textStyle.Sprint(r.Name), style.FgBlue.Sprintf("%d branches", branchCount)}
res := make([]string, 0, 3)
if icons.IsIconEnabled() {
res = append(res, textStyle.Sprint(icons.IconForRemote(r)))
}
res = append(res, textStyle.Sprint(r.Name), style.FgBlue.Sprintf("%d branches", branchCount))
return res
}