use custom help menu
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user