-
Notifications
You must be signed in to change notification settings - Fork 40
/
targets.go
77 lines (65 loc) · 1.91 KB
/
targets.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
const targetTemplate = "//%s/%s:%s"
var TargetStyle = lipgloss.NewStyle().
Height(32).Width(60).
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("63"))
type TargetModel struct {
List list.Model
}
func (m *TargetModel) Init() tea.Cmd { return nil }
func (m *TargetModel) Update(msg tea.Msg) (*TargetModel, tea.Cmd) {
var cmd tea.Cmd
m.List, cmd = m.List.Update(msg)
return m, cmd
}
func (m *TargetModel) View() string {
return TargetStyle.Render(m.List.View())
}
func InitialTarget() *TargetModel {
var (
targetsGenerator randomItemGenerator
appKeys = NewAppKeyMap()
)
// Make initial list of items
const numItems = 24
items := make([]list.Item, numItems)
for i := 0; i < numItems; i++ {
items[i] = targetsGenerator.next()
}
targetList := list.New(items, list.NewDefaultDelegate(), 60, 32)
targetList.Title = "Target"
targetList.KeyMap = DefaultListKeyMap()
targetList.AdditionalShortHelpKeys = func() []key.Binding {
return []key.Binding{
appKeys.toggleFocus,
}
}
targetList.AdditionalFullHelpKeys = func() []key.Binding {
return []key.Binding{
appKeys.toggleFocus,
}
}
targetList.SetShowHelp(false)
targetList.SetFilteringEnabled(true)
targetList.StartSpinner()
return &TargetModel{targetList}
}
type item struct {
name string `json:"__std_name"`
organelle string `json:"__std_organelle"`
cell string `json:"__std_cell"`
clade string `json:"__std_clade"`
description string `json:"__std_description"`
actions []action
}
func (i item) Title() string { return fmt.Sprintf(targetTemplate, i.cell, i.organelle, i.name) }
func (i item) Description() string { return i.description }
func (i item) FilterValue() string { return i.Title() }