@@ -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)
}
@@ -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
}
@@ -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)
@@ -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) {
@@ -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"))