Change help menus: Only display shortcuts used on the page

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-18 20:23:56 +02:00
parent 6aa377acd8
commit 969febb14c
13 changed files with 115 additions and 49 deletions
+42
View File
@@ -5,8 +5,13 @@ import (
spilltea "github.com/anotherhadi/spilltea"
"charm.land/bubbles/v2/help"
"charm.land/bubbles/v2/key"
"charm.land/bubbles/v2/viewport"
tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"
"github.com/anotherhadi/spilltea/internal/keys"
"github.com/anotherhadi/spilltea/internal/style"
)
func readDoc(name string) string {
@@ -23,14 +28,51 @@ var contentMarkdown = strings.Join([]string{
type Model struct {
viewport viewport.Model
help help.Model
width int
height int
}
func New() Model {
return Model{
viewport: viewport.New(),
help: style.NewHelp(),
}
}
func (e Model) Init() tea.Cmd {
return nil
}
func (m *Model) SetSize(w, h int) {
m.width = w
m.height = h
m.help.SetWidth(w - 2)
statusH := strings.Count(m.renderStatusBar(), "\n") + 1
frameW := windowStyle().GetHorizontalFrameSize()
frameH := windowStyle().GetVerticalFrameSize()
m.viewport.SetWidth(w - frameW)
m.viewport.SetHeight(h - frameH - statusH)
m.renderMarkdown()
}
func (m *Model) renderStatusBar() string {
return lipgloss.NewStyle().Padding(0, 1).Render(m.help.View(docsKeyMap{width: m.width}))
}
type docsKeyMap struct{ width int }
func (docsKeyMap) ShortHelp() []key.Binding {
g := keys.Keys.Global
return []key.Binding{g.Up, g.Down, g.Help}
}
func (m docsKeyMap) FullHelp() [][]key.Binding {
g := keys.Keys.Global
pageGlobals := []key.Binding{g.Up, g.Down, g.ScrollUp, g.ScrollDown}
all := append(pageGlobals, g.CommonBindings()...)
return keys.ChunkByWidth(all, m.width)
}