diff --git a/go.mod b/go.mod index 362b55b..5104136 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/a-h/templ v0.3.977 github.com/charmbracelet/bubbles v0.21.1 github.com/charmbracelet/bubbletea v1.3.10 + github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 github.com/google/uuid v1.6.0 github.com/rs/cors v1.11.1 github.com/spf13/cobra v1.10.2 @@ -28,7 +29,6 @@ require ( github.com/charmbracelet/colorprofile v0.4.1 // indirect github.com/charmbracelet/glamour v0.10.0 // indirect github.com/charmbracelet/huh v0.8.0 // indirect - github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect github.com/charmbracelet/x/ansi v0.11.5 // indirect github.com/charmbracelet/x/cellbuf v0.0.15 // indirect github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099 // indirect diff --git a/pkg/tui/views/dashboard/keys.go b/pkg/tui/views/dashboard/keys.go index 70026b3..6a832ea 100644 --- a/pkg/tui/views/dashboard/keys.go +++ b/pkg/tui/views/dashboard/keys.go @@ -6,6 +6,7 @@ import ( ) type DashboardKeyMap struct { + Help key.Binding Quit key.Binding SelectIssue key.Binding BackToList key.Binding @@ -14,6 +15,10 @@ type DashboardKeyMap struct { } var defaultDashboardKeyMap = DashboardKeyMap{ + Help: key.NewBinding( + key.WithKeys("?"), + key.WithHelp("?", "help"), + ), Quit: key.NewBinding( key.WithKeys("q", "ctrl+c"), key.WithHelp("q", "quit"), @@ -28,18 +33,32 @@ var defaultDashboardKeyMap = DashboardKeyMap{ ), ScrollUp: key.NewBinding( key.WithKeys("up", "k"), - key.WithHelp("↑/k", "scroll up"), + key.WithHelp("↑/k", "up"), ), ScrollDown: key.NewBinding( key.WithKeys("down", "j"), - key.WithHelp("↓/j", "scroll down"), + key.WithHelp("↓/j", "down"), ), } +func (m DashboardKeyMap) ShortHelp() []key.Binding { + return []key.Binding{m.ScrollDown, m.ScrollUp, m.Quit, m.Help} +} + +func (m DashboardKeyMap) FullHelp() [][]key.Binding { + return [][]key.Binding{ + {m.SelectIssue, m.BackToList}, + {m.ScrollUp, m.ScrollDown}, + {m.Help, m.Quit}, + } +} + func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd { var cmd tea.Cmd switch { + case key.Matches(msg, d.keyMap.Help): + d.help.ShowAll = !d.help.ShowAll case key.Matches(msg, d.keyMap.Quit): return tea.Quit case !d.focusedOnIssue && key.Matches(msg, d.keyMap.SelectIssue): @@ -47,9 +66,9 @@ func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd { case d.focusedOnIssue && key.Matches(msg, d.keyMap.BackToList): d.focusedOnIssue = false case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollUp): - d.issueView.Viewport.LineUp(1) + d.issueView.Viewport.ScrollUp(1) case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollDown): - d.issueView.Viewport.LineDown(1) + d.issueView.Viewport.ScrollDown(1) } return cmd diff --git a/pkg/tui/views/dashboard/model.go b/pkg/tui/views/dashboard/model.go index fed9456..d327bd1 100644 --- a/pkg/tui/views/dashboard/model.go +++ b/pkg/tui/views/dashboard/model.go @@ -4,11 +4,12 @@ import ( "github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/service" "github.com/LazyBachelor/LazyPM/pkg/tui/views/issue" + "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/list" - tea "github.com/charmbracelet/bubbletea" ) type Model struct { + help help.Model issueView issue.Model issueList list.Model keyMap DashboardKeyMap @@ -16,10 +17,6 @@ type Model struct { focusedOnIssue bool } -func (d Model) Init() tea.Cmd { - return nil -} - type ListIssue struct { models.Issue } diff --git a/pkg/tui/views/dashboard/view.go b/pkg/tui/views/dashboard/view.go index 31f7b71..6700adf 100644 --- a/pkg/tui/views/dashboard/view.go +++ b/pkg/tui/views/dashboard/view.go @@ -3,7 +3,9 @@ package dashboard import ( "context" + "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/list" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/LazyBachelor/LazyPM/internal/service" @@ -33,10 +35,12 @@ func NewDashboard(svc *service.Services) Model { issueList.Title = "Issues" issueList.Styles.Title = styles.TitleStyle + issueList.SetShowHelp(false) issueView := issue.NewIssueView(issue.Model{}) m := Model{ + help: help.New(), issueView: issueView, issueList: issueList, keyMap: defaultDashboardKeyMap, @@ -48,6 +52,10 @@ func NewDashboard(svc *service.Services) Model { return m } +func (d Model) Init() tea.Cmd { + return nil +} + func (d Model) View() string { issueView := d.issueView.View() @@ -57,7 +65,9 @@ func (d Model) View() string { issueView = styles.IssueStyle.Render(issueView) } - str := lipgloss.JoinHorizontal(lipgloss.Left, styles.AppStyle.Render(d.issueList.View()), issueView) + help := d.help.View(d.keyMap) + + str := lipgloss.JoinHorizontal(lipgloss.Left, styles.AppStyle.Render(d.issueList.View()), issueView) + "\n" + help return str }