Skip to content

Commit

Permalink
Update the stack tree styles (#383)
Browse files Browse the repository at this point in the history
* Align with other commands. Add padding.
* Remove the deleted and need sync statuses per #380
  • Loading branch information
draftcode authored Aug 7, 2024
1 parent 7b1705b commit 8491def
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions cmd/av/stack_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,72 +38,73 @@ var stackTreeCmd = &cobra.Command{
}
}

var ss []string
rootNodes := stackutils.BuildStackTreeAllBranches(tx, currentBranch, true)
for _, node := range rootNodes {
fmt.Println(stackutils.RenderTree(node, func(branchName string, isTrunk bool) string {
stbi := getStackTreeBranchInfo(repo, tx, branchName)
return renderStackTreeBranchInfo(
stackTreeStackBranchInfoStyles,
stbi,
currentBranch,
branchName,
isTrunk,
)
}))
ss = append(
ss,
stackutils.RenderTree(node, func(branchName string, isTrunk bool) string {
return renderStackTreeBranchInfo(
tx,
stackTreeStackBranchInfoStyles,
currentBranch,
branchName,
isTrunk,
)
}),
)
}
var ret string
if len(ss) != 0 {
ret = lipgloss.NewStyle().MarginTop(1).MarginBottom(1).Render(
lipgloss.JoinVertical(0, ss...),
) + "\n"
}
fmt.Print(ret)
return nil
},
}

type stackBranchInfoStyles struct {
BranchName lipgloss.Style
HEAD lipgloss.Style
Deleted lipgloss.Style
NeedSync lipgloss.Style
PullRequestLink lipgloss.Style
}

var stackTreeStackBranchInfoStyles = stackBranchInfoStyles{
BranchName: lipgloss.NewStyle().Bold(true).Foreground(colors.Green600),
HEAD: lipgloss.NewStyle().Bold(true).Foreground(colors.Cyan600),
Deleted: lipgloss.NewStyle().Bold(true).Foreground(colors.Red700),
NeedSync: lipgloss.NewStyle().Bold(true).Foreground(colors.Red700),
PullRequestLink: lipgloss.NewStyle(),
}

func renderStackTreeBranchInfo(
tx meta.ReadTx,
styles stackBranchInfoStyles,
stbi *stackTreeBranchInfo,
currentBranchName string,
branchName string,
isTrunk bool,
) string {
bi, _ := tx.Branch(branchName)

sb := strings.Builder{}
sb.WriteString(styles.BranchName.Render(branchName))
var stats []string
if branchName == currentBranchName {
stats = append(stats, styles.HEAD.Render("HEAD"))
}
if stbi.Deleted {
stats = append(stats, styles.Deleted.Render("deleted"))
}
if !isTrunk && stbi.NeedSync {
stats = append(stats, styles.NeedSync.Render("need sync"))
}
if len(stats) > 0 {
sb.WriteString(" (")
sb.WriteString(strings.Join(stats, ", "))
sb.WriteString(")")
}
sb.WriteString("\n")

if !isTrunk {
if stbi.PullRequestLink != "" {
sb.WriteString(styles.PullRequestLink.Render(stbi.PullRequestLink))
sb.WriteString("\n")
if bi.PullRequest != nil && bi.PullRequest.Permalink != "" {
sb.WriteString(styles.PullRequestLink.Render(bi.PullRequest.Permalink))
} else {
sb.WriteString(styles.PullRequestLink.Render("No pull request"))
}
sb.WriteString("\n")
}
return sb.String()
}
Expand Down

0 comments on commit 8491def

Please sign in to comment.