Skip to content

Commit

Permalink
feat: better footer + show version
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Jan 24, 2025
1 parent 98b3d56 commit 1590a7d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
45 changes: 33 additions & 12 deletions ui/components/footer/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package footer

import (
"fmt"
"path"
"strings"

bbHelp "github.com/charmbracelet/bubbles/help"
Expand Down Expand Up @@ -116,27 +117,47 @@ func (m *Model) UpdateProgramContext(ctx *context.ProgramContext) {
m.help.Styles = ctx.Styles.Help.BubbleStyles
}

func (m *Model) renderViewButton(view config.ViewType) string {
v := " PRs"
if view == config.IssuesView {
v = " Issues"
}

if m.ctx.View == view {
return m.ctx.Styles.ViewSwitcher.ActiveView.Render(v)

}
return m.ctx.Styles.ViewSwitcher.InactiveView.Render(v)
}

func (m *Model) renderViewSwitcher(ctx *context.ProgramContext) string {
var view string
if ctx.View == config.PRsView {
view += " PRs"
} else if ctx.View == config.IssuesView {
view += " Issues"
} else if ctx.View == config.RepoView {
repo := m.ctx.RepoPath
var repo string
if m.ctx.RepoPath != "" {
name := path.Base(m.ctx.RepoPath)
if m.ctx.RepoUrl != "" {
repo = git.GetRepoShortName(m.ctx.RepoUrl)
name = git.GetRepoShortName(m.ctx.RepoUrl)
}
view += fmt.Sprintf(" %s", repo)
repo = ctx.Styles.Common.FooterStyle.Render(fmt.Sprintf(" %s", name))
}

var user string
if ctx.User != "" {
user = ctx.Styles.Tabs.ViewSwitcher.Background(ctx.Theme.FaintText).Render("@" + ctx.User)
user = ctx.Styles.Common.FooterStyle.Render("@" + ctx.User)
}

return lipgloss.JoinHorizontal(lipgloss.Top, ctx.Styles.Tabs.ViewSwitcher.
Render(view), user)
view := lipgloss.JoinHorizontal(
lipgloss.Top,
ctx.Styles.ViewSwitcher.ViewsSeparator.PaddingLeft(1).Render(m.renderViewButton(config.PRsView)),
ctx.Styles.ViewSwitcher.ViewsSeparator.Render("  "),
m.renderViewButton(config.IssuesView),
lipgloss.NewStyle().Background(ctx.Styles.Common.FooterStyle.GetBackground()).Foreground(ctx.Styles.ViewSwitcher.ViewsSeparator.GetBackground()).Render(" "),
repo,
ctx.Styles.Common.FooterStyle.Foreground(m.ctx.Theme.FaintText).Render(" • "),
user,
ctx.Styles.Common.FooterStyle.Foreground(m.ctx.Theme.FaintBorder).Render(" "),
)

return ctx.Styles.ViewSwitcher.Root.Render(view)
}

func (m *Model) SetLeftSection(leftSection string) {
Expand Down
8 changes: 5 additions & 3 deletions ui/components/tabs/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ func (m Model) View(ctx *context.ProgramContext) string {
}
}

version := lipgloss.NewStyle().Foreground(ctx.Theme.SecondaryText).Render(ctx.Version)

renderedTabs := lipgloss.NewStyle().
Width(ctx.ScreenWidth).
MaxWidth(ctx.ScreenWidth).
Width(ctx.ScreenWidth - lipgloss.Width(version)).
MaxWidth(ctx.ScreenWidth - lipgloss.Width(version)).
Render(lipgloss.JoinHorizontal(lipgloss.Top, strings.Join(tabs, ctx.Styles.Tabs.TabSeparator.Render("|"))))

return ctx.Styles.Tabs.TabsRow.
Width(ctx.ScreenWidth).
MaxWidth(ctx.ScreenWidth).
Render(renderedTabs)
Render(lipgloss.JoinHorizontal(lipgloss.Center, renderedTabs, version))
}

func (m *Model) SetCurrSectionId(id int) {
Expand Down
1 change: 1 addition & 0 deletions ui/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ProgramContext struct {
MainContentHeight int
Config *config.Config
ConfigPath string
Version string
View config.ViewType
Error error
StartTask func(task Task) tea.Cmd
Expand Down
34 changes: 17 additions & 17 deletions ui/context/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ type Styles struct {
RowStyle lipgloss.Style
}
Tabs struct {
Tab lipgloss.Style
ActiveTab lipgloss.Style
TabSeparator lipgloss.Style
TabsRow lipgloss.Style
ViewSwitcher lipgloss.Style
Tab lipgloss.Style
ActiveTab lipgloss.Style
TabSeparator lipgloss.Style
TabsRow lipgloss.Style
}
ViewSwitcher struct {
ActiveView lipgloss.Style
ViewsSeparator lipgloss.Style
InactiveView lipgloss.Style
Root lipgloss.Style
ViewsSeparator lipgloss.Style
}
}

Expand Down Expand Up @@ -210,23 +212,21 @@ func InitStyles(theme theme.Theme) Styles {
BorderBottom(true).
BorderStyle(lipgloss.ThickBorder()).
BorderBottomForeground(theme.PrimaryBorder)
s.Tabs.ViewSwitcher = lipgloss.NewStyle().
Background(theme.SecondaryText).
s.ViewSwitcher.Root = lipgloss.NewStyle().
Background(s.Common.FooterStyle.GetBackground()).
Foreground(theme.InvertedText).
Padding(0, 1).
Bold(true)

s.Tabs.ActiveView = lipgloss.NewStyle().
s.ViewSwitcher.ActiveView = lipgloss.NewStyle().
Foreground(theme.PrimaryText).
Bold(true).
Background(theme.SelectedBackground)
s.Tabs.ViewsSeparator = lipgloss.NewStyle().
BorderForeground(theme.PrimaryBorder).
BorderStyle(lipgloss.NormalBorder()).
BorderRight(true)
s.Tabs.InactiveView = lipgloss.NewStyle().
Background(theme.FaintBorder)
s.ViewSwitcher.ViewsSeparator = lipgloss.NewStyle().
Background(theme.FaintBorder).
Foreground(theme.SecondaryText)
Foreground(theme.PrimaryBorder)
s.ViewSwitcher.InactiveView = lipgloss.NewStyle().
Background(theme.FaintBorder).
Foreground(theme.FaintText)

return s
}
7 changes: 7 additions & 0 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"reflect"
"runtime/debug"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -62,9 +63,15 @@ func NewModel(repoPath string, configPath string) Model {
tasks: map[string]context.Task{},
}

version := "dev"
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
version = info.Main.Version
}

m.ctx = &context.ProgramContext{
RepoPath: repoPath,
ConfigPath: configPath,
Version: version,
StartTask: func(task context.Task) tea.Cmd {
log.Debug("Starting task", "id", task.Id)
task.StartTime = time.Now()
Expand Down

0 comments on commit 1590a7d

Please sign in to comment.