mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
fix(help): wrong full help sep rendering
This commit is contained in:
committed by
Christian Rocha
parent
171a9d61a0
commit
81d444a207
+34
-26
@@ -124,28 +124,23 @@ func (m Model) ShortHelpView(bindings []key.Binding) string {
|
||||
continue
|
||||
}
|
||||
|
||||
// Sep
|
||||
var sep string
|
||||
if totalWidth > 0 && i < len(bindings) {
|
||||
sep = separator
|
||||
}
|
||||
|
||||
// Item
|
||||
str := sep +
|
||||
m.Styles.ShortKey.Inline(true).Render(kb.Help().Key) + " " +
|
||||
m.Styles.ShortDesc.Inline(true).Render(kb.Help().Desc)
|
||||
|
||||
w := lipgloss.Width(str)
|
||||
|
||||
// If adding this help item would go over the available width, stop
|
||||
// drawing.
|
||||
if m.Width > 0 && totalWidth+w > m.Width {
|
||||
// Although if there's room for an ellipsis, print that.
|
||||
tail := " " + m.Styles.Ellipsis.Inline(true).Render(m.Ellipsis)
|
||||
tailWidth := lipgloss.Width(tail)
|
||||
|
||||
if totalWidth+tailWidth < m.Width {
|
||||
// Tail
|
||||
if tail, ok := m.shouldAddItem(totalWidth, w); !ok {
|
||||
if tail != "" {
|
||||
b.WriteString(tail)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
@@ -170,8 +165,7 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
|
||||
out []string
|
||||
|
||||
totalWidth int
|
||||
sep = m.Styles.FullSeparator.Render(m.FullSeparator)
|
||||
sepWidth = lipgloss.Width(sep)
|
||||
separator = m.Styles.FullSeparator.Inline(true).Render(m.FullSeparator)
|
||||
)
|
||||
|
||||
// Iterate over groups to build columns
|
||||
@@ -179,12 +173,17 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
|
||||
if group == nil || !shouldRenderColumn(group) {
|
||||
continue
|
||||
}
|
||||
|
||||
var (
|
||||
sep string
|
||||
keys []string
|
||||
descriptions []string
|
||||
)
|
||||
|
||||
// Sep
|
||||
if totalWidth > 0 && i < len(groups) {
|
||||
sep = separator
|
||||
}
|
||||
|
||||
// Separate keys and descriptions into different slices
|
||||
for _, kb := range group {
|
||||
if !kb.Enabled() {
|
||||
@@ -194,33 +193,42 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
|
||||
descriptions = append(descriptions, kb.Help().Desc)
|
||||
}
|
||||
|
||||
// Column
|
||||
col := lipgloss.JoinHorizontal(lipgloss.Top,
|
||||
sep,
|
||||
m.Styles.FullKey.Render(strings.Join(keys, "\n")),
|
||||
m.Styles.FullKey.Render(" "),
|
||||
" ",
|
||||
m.Styles.FullDesc.Render(strings.Join(descriptions, "\n")),
|
||||
)
|
||||
w := lipgloss.Width(col)
|
||||
|
||||
// Column
|
||||
totalWidth += lipgloss.Width(col)
|
||||
if m.Width > 0 && totalWidth > m.Width {
|
||||
// Tail
|
||||
if tail, ok := m.shouldAddItem(totalWidth, w); !ok {
|
||||
if tail != "" {
|
||||
out = append(out, tail)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
totalWidth += w
|
||||
out = append(out, col)
|
||||
|
||||
// Separator
|
||||
if i < len(group)-1 {
|
||||
totalWidth += sepWidth
|
||||
if m.Width > 0 && totalWidth > m.Width {
|
||||
break
|
||||
}
|
||||
out = append(out, sep)
|
||||
}
|
||||
}
|
||||
|
||||
return lipgloss.JoinHorizontal(lipgloss.Top, out...)
|
||||
}
|
||||
|
||||
func (m Model) shouldAddItem(totalWidth, width int) (tail string, ok bool) {
|
||||
// If there's room for an ellipsis, print that.
|
||||
if m.Width > 0 && totalWidth+width > m.Width {
|
||||
tail = " " + m.Styles.Ellipsis.Inline(true).Render(m.Ellipsis)
|
||||
|
||||
if totalWidth+lipgloss.Width(tail) < m.Width {
|
||||
return tail, false
|
||||
}
|
||||
}
|
||||
return "", true
|
||||
}
|
||||
|
||||
func shouldRenderColumn(b []key.Binding) (ok bool) {
|
||||
for _, v := range b {
|
||||
if v.Enabled() {
|
||||
|
||||
Reference in New Issue
Block a user