summaryrefslogtreecommitdiff
path: root/menu/target.go
diff options
context:
space:
mode:
Diffstat (limited to 'menu/target.go')
-rw-r--r--menu/target.go36
1 files changed, 30 insertions, 6 deletions
diff --git a/menu/target.go b/menu/target.go
index 04dfea1..6d6fdec 100644
--- a/menu/target.go
+++ b/menu/target.go
@@ -4,6 +4,7 @@ import (
"github.com/charmbracelet/lipgloss"
"pik/menu/style"
"pik/model"
+ "pik/viewport"
)
var (
@@ -32,25 +33,48 @@ var (
st := lipgloss.NewStyle().PaddingLeft(1)
return st
})
+ TargetIconSelectedStyle = style.New(func() lipgloss.Style {
+ return TargetIconStyle.Get().MarginLeft(1).PaddingLeft(0)
+ })
TargetSubStyle = style.New(func() lipgloss.Style {
return lipgloss.NewStyle()
})
+ CategoryColor = lipgloss.Color("7")
+ CategoryStyle = style.New(func() lipgloss.Style {
+ return TargetStyle.Get().BorderForeground(CategoryColor).Background(CategoryColor).BorderBackground(CategoryColor)
+ })
+ OrphanCategoryStyle = style.New(func() lipgloss.Style {
+ return TargetLabelStyle.Get().PaddingLeft(1)
+ })
)
-func (m *Model) Target(t model.HydratedTarget) string {
- icon := TargetIconStyle.Render(PaddedIcon(t.Icon()))
+func (m *Model) Target(t model.HydratedTarget, header bool) string {
+ _, selection := m.Result()
+ selected := selection != nil && selection.Target() == t.Target()
+ icon := ""
+ if selected {
+ icon = TargetIconSelectedStyle.Render(PaddedIcon(viewport.Caret))
+ } else {
+ icon = TargetIconStyle.Render(PaddedIcon(t.Icon()))
+ }
selectionStyle := TargetStyle
selectionDescriptionStyle := TargetDescriptionStyle
- _, sel := m.Result()
- if sel != nil && sel.Target() == t.Target() {
+ if selected {
selectionStyle = SelectedTargetStyle
selectionDescriptionStyle = SelectedTargetDescriptionStyle
+ } else if header {
+ selectionStyle = CategoryStyle
}
var labelParts []string
labelParts = append(labelParts, icon)
- if t.Sub() != nil {
- labelParts = append(labelParts, TargetSubStyle.Render(t.Sub()...))
+ sub := t.Sub()
+ if sub != nil && sub[len(sub)-1] != t.ShortestId() {
+ labelParts = append(labelParts, TargetSubStyle.Render(sub...))
}
labelParts = append(labelParts, TargetLabelStyle.Render(t.Label()))
return lipgloss.JoinHorizontal(lipgloss.Left, selectionStyle.Render(labelParts...), selectionDescriptionStyle.Render(t.Description()))
}
+
+func (m *Model) Category(input string, desc string) string {
+ return CategoryStyle.Render(lipgloss.JoinHorizontal(lipgloss.Left, OrphanCategoryStyle.Render(input), TargetDescriptionStyle.Render(desc)))
+}