diff --git a/tui/bubble.go b/tui/bubble.go index 76d27945d8df3d226ff5624411f674d098feb862..8528c864e0b5244431ddfb5c91b083f6b202fb8b 100644 --- a/tui/bubble.go +++ b/tui/bubble.go @@ -101,6 +101,13 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.WindowSizeMsg: b.width = msg.Width b.height = msg.Height + if b.state == loadedState { + ab, cmd := b.boxes[b.activeBox].Update(msg) + b.boxes[b.activeBox] = ab + if cmd != nil { + cmds = append(cmds, cmd) + } + } case selection.SelectedMsg: b.activeBox = 1 rb := b.repoMenu[msg.Index].bubble @@ -121,29 +128,40 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return b, tea.Batch(cmds...) } -func (b *Bubble) viewForBox(i int, width int) string { +func (b *Bubble) viewForBox(i int, width int, height int) string { var ls lipgloss.Style if i == b.activeBox { - ls = activeBoxStyle.Width(width) + ls = activeBoxStyle.Copy() } else { - ls = inactiveBoxStyle.Width(width) + ls = inactiveBoxStyle.Copy() + } + ls.Width(width) + if height > 0 { + ls.Height(height).MarginBottom(2) } return ls.Render(b.boxes[i].View()) } func (b *Bubble) View() string { - h := headerStyle.Width(b.width - horizontalPadding).Render(b.config.Name) - f := footerStyle.Render("") + w := b.width - 3 + f := "" s := "" content := "" + h := headerStyle.Width(w - 2).Render(b.config.Name) + f += footerHighlightStyle.Bold(true).Render("tab ") + f += footerStyle.Render("section • ") + f += footerHighlightStyle.Bold(true).Render("j/k ") + f += footerStyle.Render("down/up • ") + f += footerHighlightStyle.Bold(true).Render("q ") + f += footerStyle.Render("quit") switch b.state { case loadedState: - lb := b.viewForBox(0, boxLeftWidth) - rb := b.viewForBox(1, boxRightWidth) + lb := b.viewForBox(0, boxLeftWidth, 0) + rb := b.viewForBox(1, b.width-boxLeftWidth-10, b.height-8) s += lipgloss.JoinHorizontal(lipgloss.Top, lb, rb) case errorState: s += errorStyle.Render(fmt.Sprintf("Bummer: %s", b.error)) } - content = h + "\n\n" + s + "\n" + f - return appBoxStyle.Render(content) + content = h + "\n" + s + "\n" + f + return appBoxStyle.Width(w).Height(b.height - 2).BorderStyle(lipgloss.RoundedBorder()).Render(content) } diff --git a/tui/bubbles/repo/bubble.go b/tui/bubbles/repo/bubble.go index be50cfeaff4975c0cb3aa0de59e401cf7ce5b16d..8c30c60680e66d7d348a53d81589e46267917b0a 100644 --- a/tui/bubbles/repo/bubble.go +++ b/tui/bubbles/repo/bubble.go @@ -20,17 +20,26 @@ type Bubble struct { name string repo *git.Repo readmeViewport *ViewportBubble + readme string + height int + heightMargin int + width int + widthMargin int } -func NewBubble(rs *git.RepoSource, name string, width int, height int, tmp interface{}) *Bubble { +func NewBubble(rs *git.RepoSource, name string, width, wm, height, hm int, tmp interface{}) *Bubble { return &Bubble{ templateObject: tmp, repoSource: rs, name: name, + height: height, + width: width, + heightMargin: hm, + widthMargin: wm, readmeViewport: &ViewportBubble{ Viewport: &viewport.Model{ - Width: width, - Height: height, + Width: width - wm, + Height: height - hm, }, }, } @@ -42,6 +51,16 @@ func (b *Bubble) Init() tea.Cmd { func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd + switch msg := msg.(type) { + case tea.WindowSizeMsg: + b.readmeViewport.Viewport.Width = msg.Width - b.widthMargin + b.readmeViewport.Viewport.Height = msg.Height - b.heightMargin + md, err := b.glamourize(b.readme) + if err != nil { + return b, nil + } + b.readmeViewport.Viewport.SetContent(md) + } rv, cmd := b.readmeViewport.Update(msg) b.readmeViewport = rv.(*ViewportBubble) if cmd != nil { @@ -73,12 +92,13 @@ func (b *Bubble) setupCmd() tea.Msg { return ErrMsg{err} } } + b.readme = md md, err = b.glamourize(md) if err != nil { return ErrMsg{err} } - b.GotoTop() b.readmeViewport.Viewport.SetContent(md) + b.GotoTop() return nil } @@ -97,9 +117,10 @@ func (b *Bubble) templatize(mdt string) (string, error) { func (b *Bubble) glamourize(md string) (string, error) { tr, err := glamour.NewTermRenderer( - glamour.WithAutoStyle(), - glamour.WithWordWrap(b.readmeViewport.Viewport.Width), + glamour.WithStandardStyle("dark"), + glamour.WithWordWrap(b.width-b.widthMargin), ) + if err != nil { return "", err } diff --git a/tui/bubbles/repo/style.go b/tui/bubbles/repo/style.go deleted file mode 100644 index 2789bdad3b05efe1bbcd4e77c8b416fc54847b4a..0000000000000000000000000000000000000000 --- a/tui/bubbles/repo/style.go +++ /dev/null @@ -1,25 +0,0 @@ -package repo - -import ( - "github.com/charmbracelet/lipgloss" -) - -var commitBoxStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#FFFFFF")). - BorderStyle(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("#670083")). - Padding(1) -var commitRepoNameStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#8922A5")) -var commitAuthorStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#670083")) -var commitAuthorEmailStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#781194")) -var commitDateStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#781194")) -var commitCommentStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#606060")). - BorderStyle(lipgloss.Border{Left: ">"}). - PaddingLeft(1). - PaddingBottom(0). - Margin(0) diff --git a/tui/commands.go b/tui/commands.go index d249c2077e180d5f0ccf33912b9d736cd6042dcc..68f54fd6b2765436a897c948087f23babff971ec 100644 --- a/tui/commands.go +++ b/tui/commands.go @@ -45,13 +45,11 @@ func (b *Bubble) setupCmd() tea.Msg { } } var tmplConfig *Config - h := b.height - verticalPadding - viewportHeightConstant - w := boxRightWidth - 2 for _, me := range mes { if me.Repo == "config" { tmplConfig = b.config } - rb := repo.NewBubble(b.repoSource, me.Repo, w, h, tmplConfig) + rb := repo.NewBubble(b.repoSource, me.Repo, b.width, boxLeftWidth+12, b.height, 12, tmplConfig) initCmd := rb.Init() msg := initCmd() switch msg := msg.(type) { diff --git a/tui/style.go b/tui/style.go index 7787deaa80d34c32041c74c752455616941365b7..1a45f6c4c55cd84194312ac59f50c164ca00cb41 100644 --- a/tui/style.go +++ b/tui/style.go @@ -39,10 +39,10 @@ var normalStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FFFFFF")) var footerStyle = lipgloss.NewStyle(). - BorderForeground(lipgloss.Color("#6D6D6D")). - BorderLeft(true). - Foreground(lipgloss.Color("#373737")). - Bold(true) + Foreground(lipgloss.Color("#373737")) + +var footerHighlightStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#DCDCDC")) var errorStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FF00000"))