copied the dashboard and made a keybinding to change back and forth between them; ready to turn dashboard2 into a boardview dashboard

This commit is contained in:
viljarb
2026-03-02 19:53:42 +01:00
parent cb10aeff6b
commit 1d5b7e0860
13 changed files with 1651 additions and 17 deletions

View File

@@ -0,0 +1,106 @@
package dashboard2
import (
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
"github.com/charmbracelet/lipgloss"
)
type HelpBar struct {
keyMap DashboardKeyMap
showAll bool
width int
}
func NewHelpBar(keyMap DashboardKeyMap) HelpBar {
return HelpBar{keyMap: keyMap}
}
func (h *HelpBar) SetWidth(width int) {
h.width = width
}
func (h HelpBar) View() string {
if h.width == 0 {
return ""
}
if h.showAll {
return h.fullHelp()
}
return h.shortHelp()
}
func (h HelpBar) shortHelp() string {
keys := []string{
styles.HighlightKey("tab") + " switch",
styles.HighlightKey("ctrl+1") + " dash1",
styles.HighlightKey("↑/k") + " up",
styles.HighlightKey("↓/j") + " down",
styles.HighlightKey("pgup/pgdn") + " page",
styles.HighlightKey("a") + " add",
styles.HighlightKey("e/d/s/p/t") + " edit",
styles.HighlightKey("x") + " delete",
styles.HighlightKey("q") + " quit",
styles.HighlightKey("?") + " help",
}
content := lipgloss.JoinHorizontal(lipgloss.Left, keys...)
return lipgloss.NewStyle().
Border(lipgloss.Border{Top: "─"}, true, false, false, false).
BorderForeground(styles.SecondaryBorder).
Padding(0, 1).
Width(h.width).
Render(content)
}
func (h HelpBar) fullHelp() string {
keyStyle := lipgloss.NewStyle().Width(8).Align(lipgloss.Right)
descStyle := lipgloss.NewStyle().Width(12)
renderHelpItem := func(key, desc string) string {
return lipgloss.JoinHorizontal(
lipgloss.Left,
keyStyle.Render(styles.HighlightKey(key)),
" ",
descStyle.Render(desc),
)
}
renderRow := func(leftKey, leftDesc, rightKey, rightDesc string) string {
leftItem := renderHelpItem(leftKey, leftDesc)
rightItem := renderHelpItem(rightKey, rightDesc)
return lipgloss.JoinHorizontal(lipgloss.Left, leftItem, " ", rightItem)
}
rows := []string{
renderRow("tab", "switch window", "↑/k", "up"),
renderRow("enter", "view issue", "↓/j", "down"),
renderRow("pgup", "page up", "pgdn", "page down"),
renderRow("b", "back to list", "a", "add issue"),
renderRow("e", "edit title", "d", "edit description"),
renderRow("s", "change status", "p", "change priority"),
renderRow("t", "change type", "x", "delete issue"),
renderRow("ctrl+1", "dashboard 1", "q", "quit"),
renderRow("?", "help", "", ""),
}
content := lipgloss.JoinVertical(lipgloss.Left, rows...)
return lipgloss.NewStyle().
Border(lipgloss.Border{Top: "─"}, true, false, false, false).
BorderForeground(styles.SecondaryBorder).
Padding(0, 1).
Width(h.width).
Render(content)
}
func (h HelpBar) Height() int {
if h.width == 0 {
return 0
}
return lipgloss.Height(h.View())
}
func (h HelpBar) IsExpanded() bool {
return h.showAll
}
func (h *HelpBar) ToggleHelp() {
h.showAll = !h.showAll
}