summaryrefslogtreecommitdiff
path: root/menu/target.go
blob: 04dfea10968ce9d8803e2195d345e994cb08b7af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
		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 != nil && 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()))
}