本文整理汇总了Golang中github.com/scottweston/powerline-shell-go/powerline.Segment.Foreground方法的典型用法代码示例。如果您正苦于以下问题:Golang Segment.Foreground方法的具体用法?Golang Segment.Foreground怎么用?Golang Segment.Foreground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/scottweston/powerline-shell-go/powerline.Segment
的用法示例。
在下文中一共展示了Segment.Foreground方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addHgInfo
func addHgInfo(conf config.Configuration, p powerline.Powerline) *powerline.Segment {
var fmt_str string
segment := powerline.Segment{}
branch_colour := conf.Colours.Hg.BackgroundDefault
text_colour := conf.Colours.Hg.Text
hg, err := exec.Command("hg", "sum", "--color=never", "-y").Output()
if err == nil {
// branch:
reBranch := regexp.MustCompile(`(?m)^branch: (.*)$`)
matchBranch := reBranch.FindStringSubmatch(string(hg))
// commit:
// %d modified, %d added, %d removed, %d renamed, %d copied
// %d deleted, %d unknown, %d unresolved, %d subrepos
reModifed := regexp.MustCompile(`(?m)^commit:.* (.*) modified`)
res_mod := reModifed.FindStringSubmatch(string(hg))
reUntracked := regexp.MustCompile(`(?m)^commit:.* (.*) unknown`)
res_untrk := reUntracked.FindStringSubmatch(string(hg))
reAdded := regexp.MustCompile(`(?m)^commit:.* (.*) added`)
res_added := reAdded.FindStringSubmatch(string(hg))
reRemoved := regexp.MustCompile(`(?m)^commit:.* (.*) removed`)
res_remove := reRemoved.FindStringSubmatch(string(hg))
reClean := regexp.MustCompile(`(?m)^commit:.*\(clean\)`)
res_clean := reClean.FindStringSubmatch(string(hg))
// update:
reUpdate := regexp.MustCompile(`(?m)^update: (.*) new`)
res_update := reUpdate.FindStringSubmatch(string(hg))
// phases:
rePublic := regexp.MustCompile(`(?m)^phases:.* (.*) public`)
res_public := rePublic.FindStringSubmatch(string(hg))
reDraft := regexp.MustCompile(`(?m)^phases:.* (.*) draft`)
res_draft := reDraft.FindStringSubmatch(string(hg))
reSecret := regexp.MustCompile(`(?m)^phases:.* (.*) secret`)
res_secret := reSecret.FindStringSubmatch(string(hg))
if len(res_clean) == 0 {
branch_colour = conf.Colours.Hg.BackgroundChanges
}
segment.Background = branch_colour
segment.Foreground = text_colour
segment.Weight = conf.Weights.Segments.Hg
// branch name
if len(matchBranch) > 0 {
branch := matchBranch[1]
branch_fmt := branch
if conf.BranchMaxLength > 3 {
if len(branch) > conf.BranchMaxLength {
sml := int(conf.BranchMaxLength/2 - 1)
if sml > 0 {
branch_fmt = branch[0:sml] + p.Ellipsis + branch[len(branch)-sml:]
}
}
}
if branch != "default" {
fmt_str = p.Branch + " " + branch_fmt
} else {
fmt_str = branch_fmt
}
segment.Parts = append(segment.Parts, powerline.Part{Text: fmt_str, Weight: conf.Weights.Parts.Branch})
}
// phases
if len(res_public) > 0 || len(res_draft) > 0 || len(res_secret) > 0 {
var public int = 0
var draft int = 0
var secret int = 0
if len(res_public) > 0 {
public, _ = strconv.Atoi(res_public[1])
}
if len(res_draft) > 0 {
draft, _ = strconv.Atoi(res_draft[1])
}
if len(res_secret) > 0 {
secret, _ = strconv.Atoi(res_secret[1])
}
total := public + draft + secret
if total == 1 {
fmt_str = p.Phases
} else {
fmt_str = fmt.Sprintf("%d%s", total, p.Phases)
}
segment.Parts = append(segment.Parts, powerline.Part{Text: fmt_str, Weight: conf.Weights.Parts.Phases})
}
// updated files
if len(res_update) > 0 {
if res_update[1] != "1" {
fmt_str = fmt.Sprintf("%s%s", res_update[1], p.Behind)
} else {
fmt_str = p.Behind
}
segment.Parts = append(segment.Parts, powerline.Part{Text: fmt_str, Weight: conf.Weights.Parts.Sync})
//.........这里部分代码省略.........
示例2: addGitInfo
func addGitInfo(conf config.Configuration, porcelain string, p powerline.Powerline) *powerline.Segment {
var fmt_str string
segment := powerline.Segment{}
branch_colour := conf.Colours.Git.BackgroundDefault
text_colour := conf.Colours.Git.Text
// what branch
reBranch := regexp.MustCompile(`(?m)^## (([^ \.\n]+).*|.* on (\S+))$`)
matchBranch := reBranch.FindStringSubmatch(porcelain)
// detached?
reDetached := regexp.MustCompile(`(?m)^## .* \(no branch\)`)
matchDetached := reDetached.FindStringSubmatch(porcelain)
// are we ahead/behind
reStatus := regexp.MustCompile(`(?m)^## .* \[(ahead|behind) ([0-9]+)\]`)
matchStatus := reStatus.FindStringSubmatch(porcelain)
// renamed files
rename, _ := regexp.Compile(`(?m)^R. `)
rename_res := rename.FindAllString(porcelain, -1)
// added files
add, _ := regexp.Compile(`(?m)^A. `)
add_res := add.FindAllString(porcelain, -1)
// modified files
mod, _ := regexp.Compile(`(?m)^.M `)
mod_res := mod.FindAllString(porcelain, -1)
// uncommitted files
uncom, _ := regexp.Compile(`(?m)^\?\? `)
uncom_res := uncom.FindAllString(porcelain, -1)
// removed files
del, _ := regexp.Compile(`(?m)^(D.|.D) `)
del_res := del.FindAllString(porcelain, -1)
// conflicted files
cfd, _ := regexp.Compile(`(?m)^DD|AU|UD|UA|DU|AA|UU .*$`)
cfd_res := cfd.FindAllString(porcelain, -1)
// any changes at all?
if len(rename_res) > 0 || len(add_res) > 0 || len(mod_res) > 0 || len(uncom_res) > 0 || len(del_res) > 0 || len(cfd_res) > 0 {
branch_colour = conf.Colours.Git.BackgroundChanges
}
segment.Background = branch_colour
segment.Foreground = text_colour
segment.Weight = conf.Weights.Segments.Git
// branch name
if len(matchBranch) > 0 {
branch := matchBranch[2]
branch_fmt := branch
if conf.BranchMaxLength > 3 {
if len(branch) > conf.BranchMaxLength {
sml := int(conf.BranchMaxLength/2 - 1)
if sml > 0 {
branch_fmt = branch[0:sml] + p.Ellipsis + branch[len(branch)-sml:]
}
}
}
if len(matchDetached) > 0 {
fmt_str = p.Detached + " "
} else {
fmt_str = ""
}
if branch != "master" {
fmt_str = fmt.Sprintf("%s%s ", fmt_str, p.Branch)
}
fmt_str = fmt.Sprintf("%s%s", fmt_str, branch_fmt)
segment.Parts = append(segment.Parts, powerline.Part{Text: fmt_str, Weight: conf.Weights.Parts.Branch})
}
// ahead/behind
if len(matchStatus) > 0 {
num, _ := strconv.Atoi(matchStatus[2])
if matchStatus[1] == "behind" {
if num > 1 {
fmt_str = fmt.Sprintf("%s%s", matchStatus[2], p.Behind)
} else {
fmt_str = p.Behind
}
} else if matchStatus[1] == "ahead" {
if num > 1 {
fmt_str = fmt.Sprintf("%s%s", matchStatus[2], p.Ahead)
} else {
fmt_str = p.Ahead
}
} else {
fmt_str = "unk"
}
segment.Parts = append(segment.Parts, powerline.Part{Text: fmt_str, Weight: conf.Weights.Parts.Sync})
}
//.........这里部分代码省略.........