use custom help menu
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/a-h/templ v0.3.977
|
github.com/a-h/templ v0.3.977
|
||||||
github.com/charmbracelet/bubbles v0.21.1
|
github.com/charmbracelet/bubbles v0.21.1
|
||||||
github.com/charmbracelet/bubbletea v1.3.10
|
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/google/uuid v1.6.0
|
||||||
github.com/rs/cors v1.11.1
|
github.com/rs/cors v1.11.1
|
||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
@@ -28,7 +29,6 @@ require (
|
|||||||
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||||
github.com/charmbracelet/glamour v0.10.0 // indirect
|
github.com/charmbracelet/glamour v0.10.0 // indirect
|
||||||
github.com/charmbracelet/huh v0.8.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/ansi v0.11.5 // indirect
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
||||||
github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099 // indirect
|
github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099 // indirect
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DashboardKeyMap struct {
|
type DashboardKeyMap struct {
|
||||||
|
Help key.Binding
|
||||||
Quit key.Binding
|
Quit key.Binding
|
||||||
SelectIssue key.Binding
|
SelectIssue key.Binding
|
||||||
BackToList key.Binding
|
BackToList key.Binding
|
||||||
@@ -14,6 +15,10 @@ type DashboardKeyMap struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defaultDashboardKeyMap = DashboardKeyMap{
|
var defaultDashboardKeyMap = DashboardKeyMap{
|
||||||
|
Help: key.NewBinding(
|
||||||
|
key.WithKeys("?"),
|
||||||
|
key.WithHelp("?", "help"),
|
||||||
|
),
|
||||||
Quit: key.NewBinding(
|
Quit: key.NewBinding(
|
||||||
key.WithKeys("q", "ctrl+c"),
|
key.WithKeys("q", "ctrl+c"),
|
||||||
key.WithHelp("q", "quit"),
|
key.WithHelp("q", "quit"),
|
||||||
@@ -28,18 +33,32 @@ var defaultDashboardKeyMap = DashboardKeyMap{
|
|||||||
),
|
),
|
||||||
ScrollUp: key.NewBinding(
|
ScrollUp: key.NewBinding(
|
||||||
key.WithKeys("up", "k"),
|
key.WithKeys("up", "k"),
|
||||||
key.WithHelp("↑/k", "scroll up"),
|
key.WithHelp("↑/k", "up"),
|
||||||
),
|
),
|
||||||
ScrollDown: key.NewBinding(
|
ScrollDown: key.NewBinding(
|
||||||
key.WithKeys("down", "j"),
|
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 {
|
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case key.Matches(msg, d.keyMap.Help):
|
||||||
|
d.help.ShowAll = !d.help.ShowAll
|
||||||
case key.Matches(msg, d.keyMap.Quit):
|
case key.Matches(msg, d.keyMap.Quit):
|
||||||
return tea.Quit
|
return tea.Quit
|
||||||
case !d.focusedOnIssue && key.Matches(msg, d.keyMap.SelectIssue):
|
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):
|
case d.focusedOnIssue && key.Matches(msg, d.keyMap.BackToList):
|
||||||
d.focusedOnIssue = false
|
d.focusedOnIssue = false
|
||||||
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollUp):
|
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):
|
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollDown):
|
||||||
d.issueView.Viewport.LineDown(1)
|
d.issueView.Viewport.ScrollDown(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue"
|
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue"
|
||||||
|
"github.com/charmbracelet/bubbles/help"
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
|
help help.Model
|
||||||
issueView issue.Model
|
issueView issue.Model
|
||||||
issueList list.Model
|
issueList list.Model
|
||||||
keyMap DashboardKeyMap
|
keyMap DashboardKeyMap
|
||||||
@@ -16,10 +17,6 @@ type Model struct {
|
|||||||
focusedOnIssue bool
|
focusedOnIssue bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Model) Init() tea.Cmd {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListIssue struct {
|
type ListIssue struct {
|
||||||
models.Issue
|
models.Issue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package dashboard
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/bubbles/help"
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
@@ -33,10 +35,12 @@ func NewDashboard(svc *service.Services) Model {
|
|||||||
|
|
||||||
issueList.Title = "Issues"
|
issueList.Title = "Issues"
|
||||||
issueList.Styles.Title = styles.TitleStyle
|
issueList.Styles.Title = styles.TitleStyle
|
||||||
|
issueList.SetShowHelp(false)
|
||||||
|
|
||||||
issueView := issue.NewIssueView(issue.Model{})
|
issueView := issue.NewIssueView(issue.Model{})
|
||||||
|
|
||||||
m := Model{
|
m := Model{
|
||||||
|
help: help.New(),
|
||||||
issueView: issueView,
|
issueView: issueView,
|
||||||
issueList: issueList,
|
issueList: issueList,
|
||||||
keyMap: defaultDashboardKeyMap,
|
keyMap: defaultDashboardKeyMap,
|
||||||
@@ -48,6 +52,10 @@ func NewDashboard(svc *service.Services) Model {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Model) Init() tea.Cmd {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d Model) View() string {
|
func (d Model) View() string {
|
||||||
issueView := d.issueView.View()
|
issueView := d.issueView.View()
|
||||||
|
|
||||||
@@ -57,7 +65,9 @@ func (d Model) View() string {
|
|||||||
issueView = styles.IssueStyle.Render(issueView)
|
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
|
return str
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user