Skip to content

Commit

Permalink
date control help
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Oct 28, 2024
1 parent 80b9731 commit 2ba9d2d
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions cmd/slackdump/internal/ui/updaters/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"strings"
"time"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui"
Expand All @@ -20,6 +22,8 @@ type DateModel struct {
finishing bool
timeEnabled bool
state state
keymap dateKeymap
help help.Model
}

func NewDTTM(ptrTime *time.Time) DateModel {
Expand All @@ -40,7 +44,36 @@ func NewDTTM(ptrTime *time.Time) DateModel {
tm: t,
focusstyle: ui.DefaultTheme().Focused.Border,
blurstyle: ui.DefaultTheme().Blurred.Border,
keymap: defaultDateKeymap(),
timeEnabled: true,
help: help.New(),
}
}

type dateKeymap struct {
NextField key.Binding
PrevField key.Binding
Arrows key.Binding
Select key.Binding
Cancel key.Binding
Clear key.Binding
}

func defaultDateKeymap() dateKeymap {
return dateKeymap{
NextField: key.NewBinding(key.WithKeys("tab"), key.WithHelp("↹", "next")),
PrevField: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("⇧ + ↹", "prev")),
Arrows: key.NewBinding(key.WithKeys("esc", "ctrl+c", "q"), key.WithHelp("←↑↓→", "move")),
Select: key.NewBinding(key.WithKeys("enter"), key.WithHelp("↵", "select")),
Cancel: key.NewBinding(key.WithKeys("esc", "ctrl+c", "q"), key.WithHelp("Esc", "cancel")),
Clear: key.NewBinding(key.WithKeys("backspace"), key.WithHelp("backspace", "clear")),
}
}

func (m dateKeymap) keybindings() [][]key.Binding {
return [][]key.Binding{
{m.NextField, m.PrevField, m.Arrows},
{m.Select, m.Cancel, m.Clear},
}
}

Expand Down Expand Up @@ -127,7 +160,7 @@ func (m DateModel) View() string {

var b strings.Builder

help := ui.DefaultTheme().Help.Ellipsis.Render("arrow keys: adjust • tab/shift+tab: switch fields\nenter: select • backspace: clear • esc: cancel")
help := m.help.FullHelpView(m.keymap.keybindings())

var dateStyle lipgloss.Style
var timeStyle lipgloss.Style
Expand All @@ -147,11 +180,7 @@ func (m DateModel) View() string {
timeStyle.Render(m.tm.View()),
))
} else {
b.WriteString(lipgloss.JoinVertical(
lipgloss.Center,
dateStyle.Render(m.dm.View()),
help,
))
b.WriteString(dateStyle.Render(m.dm.View()))
}
return b.String()
return lipgloss.JoinVertical(lipgloss.Left, b.String(), help)
}

0 comments on commit 2ba9d2d

Please sign in to comment.