summaryrefslogtreecommitdiff
path: root/menu/target.go
diff options
context:
space:
mode:
Diffstat (limited to 'menu/target.go')
-rw-r--r--menu/target.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/menu/target.go b/menu/target.go
new file mode 100644
index 0000000..b17ed68
--- /dev/null
+++ b/menu/target.go
@@ -0,0 +1,56 @@
+package menu
+
+import (
+ "github.com/charmbracelet/lipgloss"
+ "pik/menu/style"
+ "pik/model"
+)
+
+var (
+ TargetBackgroundColor = lipgloss.Color("8")
+ SelectedTargetBackgroundColor = lipgloss.Color("2")
+ TargetStyle = style.New(func() lipgloss.Style {
+ st := lipgloss.NewStyle().Border(lipgloss.OuterHalfBlockBorder(), false, false, false, true).BorderBackground(TargetBackgroundColor).Background(TargetBackgroundColor)
+ return st
+ })
+ SelectedTargetStyle = style.New(func() lipgloss.Style {
+ return TargetStyle.Get().BorderBackground(SelectedTargetBackgroundColor).Background(SelectedTargetBackgroundColor)
+ })
+ TargetLabelStyle = style.New(func() lipgloss.Style {
+ st := lipgloss.NewStyle().MarginRight(1)
+ return st
+ })
+ TargetDescriptionStyle = style.New(func() lipgloss.Style {
+ st := lipgloss.NewStyle().Faint(true).MarginLeft(1)
+ return st
+ })
+ SelectedTargetDescriptionStyle = style.New(func() lipgloss.Style {
+ st := TargetDescriptionStyle.Get().Faint(false)
+ return st
+ })
+ TargetIconStyle = style.New(func() lipgloss.Style {
+ st := lipgloss.NewStyle().PaddingLeft(1)
+ return st
+ })
+ TargetSubStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+)
+
+func (m *Model) Target(t model.HydratedTarget) string {
+ icon := TargetIconStyle.Render(PaddedIcon(t.Icon()))
+ selectionStyle := TargetStyle
+ selectionDescriptionStyle := TargetDescriptionStyle
+ _, sel := m.Result()
+ if sel.Target() == t.Target() {
+ selectionStyle = SelectedTargetStyle
+ selectionDescriptionStyle = SelectedTargetDescriptionStyle
+ }
+ var labelParts []string
+ labelParts = append(labelParts, icon)
+ if t.Sub() != nil {
+ labelParts = append(labelParts, TargetSubStyle.Render(t.Sub()...))
+ }
+ labelParts = append(labelParts, TargetLabelStyle.Render(t.Label()))
+ return lipgloss.JoinHorizontal(lipgloss.Left, selectionStyle.Render(labelParts...), selectionDescriptionStyle.Render(t.Description()))
+}