Skip to content

Commit

Permalink
Truncate long repos names in the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Sep 17, 2021
1 parent c61938d commit 943f941
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions tui/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ func (b *Bubble) viewForBox(i int) string {
isActive := i == b.activeBox
switch box := b.boxes[i].(type) {
case *selection.Bubble:
// Menu
var s lipgloss.Style
s = b.styles.Menu
if isActive {
s = s.Copy().BorderForeground(b.styles.ActiveBorderColor)
}
return s.Render(box.View())
case *repo.Bubble:
// Repo details
box.Active = isActive
return box.View()
default:
Expand Down
20 changes: 14 additions & 6 deletions tui/bubbles/selection/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package selection

import (
"soft-serve/tui/style"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/truncate"
)

type SelectedMsg struct {
Expand Down Expand Up @@ -34,19 +37,24 @@ func (b *Bubble) Init() tea.Cmd {
}

func (b Bubble) View() string {
s := ""
s := strings.Builder{}
repoNameMaxWidth := b.styles.Menu.GetWidth() - // menu width
b.styles.Menu.GetHorizontalPadding() - // menu padding
lipgloss.Width(b.styles.MenuCursor.String()) - // cursor
b.styles.MenuItem.GetHorizontalFrameSize() // menu item gaps
for i, item := range b.Items {
item := truncate.StringWithTail(item, uint(repoNameMaxWidth), "…")
if i == b.SelectedItem {
s += b.styles.MenuCursor.String()
s += b.styles.SelectedMenuItem.Render(item)
s.WriteString(b.styles.MenuCursor.String())
s.WriteString(b.styles.SelectedMenuItem.Render(item))
} else {
s += b.styles.MenuItem.Render(item)
s.WriteString(b.styles.MenuItem.Render(item))
}
if i < len(b.Items)-1 {
s += "\n"
s.WriteRune('\n')
}
}
return s
return s.String()
}

func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand Down

0 comments on commit 943f941

Please sign in to comment.