mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(tui): add [S]/[A] kind prefix in All tab and group by kind
In the All (resources) tab: - Show [S] prefix for skills and [A] prefix for agents - Group items by kind: skills first, agents second - Each kind block preserves original repo grouping with kind-prefixed headers (e.g. 'Skills · standalone') In Skills/Agents tabs: no prefix shown (context is clear). Detail panel now shows 'Skill' or 'Agent' kind label in the status bits alongside remote/local/tracked. Spinner message is now tab-aware: 'Loading resources/skills/agents'. Implementation uses a shared *listTab pointer between the model and delegate so the delegate reads current tab state without needing SetDelegate() on every tab switch.
This commit is contained in:
+40
-14
@@ -89,6 +89,7 @@ type listTUIModel struct {
|
||||
|
||||
// Tab filter — pre-filters allItems by kind (All / Skills / Agents)
|
||||
activeTab listTab // currently selected tab
|
||||
activeTabP *listTab // shared pointer for delegate to read current tab
|
||||
tabCounts [3]int // cached counts: [all, skills, agents]
|
||||
tabFiltered []skillItem // cached result of tabFilteredItems(); set by applyFilter()
|
||||
|
||||
@@ -124,7 +125,21 @@ type listTUIModel struct {
|
||||
// When loadFn is non-nil, skills are loaded asynchronously inside the TUI (spinner shown).
|
||||
// When loadFn is nil, skills/totalCount are used directly (pre-loaded).
|
||||
func newListTUIModel(loadFn listLoadFn, skills []skillItem, totalCount int, modeLabel, sourcePath, agentsSourcePath string, targets map[string]config.TargetConfig, initialKind resourceKindFilter) listTUIModel {
|
||||
delegate := listSkillDelegate{}
|
||||
// Map CLI kind filter to initial tab
|
||||
var initTab listTab
|
||||
switch initialKind {
|
||||
case kindAgents:
|
||||
initTab = listTabAgents
|
||||
case kindSkills:
|
||||
initTab = listTabSkills
|
||||
default:
|
||||
initTab = listTabAll
|
||||
}
|
||||
|
||||
// Shared pointer lets the delegate read the current tab without re-creation.
|
||||
tabPtr := new(listTab)
|
||||
*tabPtr = initTab
|
||||
delegate := listSkillDelegate{activeTab: tabPtr}
|
||||
|
||||
// Build initial item set (empty if async loading)
|
||||
var items []list.Item
|
||||
@@ -156,17 +171,6 @@ func newListTUIModel(loadFn listLoadFn, skills []skillItem, totalCount int, mode
|
||||
fi.Cursor.Style = tc.Filter
|
||||
fi.Placeholder = "filter or t:tracked g:group r:repo k:kind"
|
||||
|
||||
// Map CLI kind filter to initial tab
|
||||
var initTab listTab
|
||||
switch initialKind {
|
||||
case kindAgents:
|
||||
initTab = listTabAgents
|
||||
case kindSkills:
|
||||
initTab = listTabSkills
|
||||
default:
|
||||
initTab = listTabAll
|
||||
}
|
||||
|
||||
m := listTUIModel{
|
||||
list: l,
|
||||
totalCount: totalCount,
|
||||
@@ -175,6 +179,7 @@ func newListTUIModel(loadFn listLoadFn, skills []skillItem, totalCount int, mode
|
||||
agentsSourcePath: agentsSourcePath,
|
||||
targets: targets,
|
||||
activeTab: initTab,
|
||||
activeTabP: tabPtr,
|
||||
detailCache: make(map[string]*detailData),
|
||||
loading: loadFn != nil,
|
||||
loadSpinner: sp,
|
||||
@@ -206,9 +211,20 @@ func (m *listTUIModel) recomputeTabCounts() {
|
||||
}
|
||||
|
||||
// tabFilteredItems returns the subset of allItems matching the active tab.
|
||||
// For listTabAll, items are reordered so skills come first then agents,
|
||||
// keeping each kind's original order intact.
|
||||
func (m *listTUIModel) tabFilteredItems() []skillItem {
|
||||
if m.activeTab == listTabAll {
|
||||
return m.allItems
|
||||
skills := make([]skillItem, 0, m.tabCounts[1])
|
||||
agents := make([]skillItem, 0, m.tabCounts[2])
|
||||
for _, item := range m.allItems {
|
||||
if item.entry.Kind == "agent" {
|
||||
agents = append(agents, item)
|
||||
} else {
|
||||
skills = append(skills, item)
|
||||
}
|
||||
}
|
||||
return append(skills, agents...)
|
||||
}
|
||||
wantAgent := m.activeTab == listTabAgents
|
||||
cap := m.tabCounts[1]
|
||||
@@ -399,12 +415,14 @@ func (m listTUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, tea.Quit
|
||||
case "tab":
|
||||
m.activeTab = (m.activeTab + 1) % 3
|
||||
*m.activeTabP = m.activeTab
|
||||
m.applyFilter()
|
||||
m.updateTitle()
|
||||
skipGroupItem(&m.list, 1)
|
||||
return m, nil
|
||||
case "shift+tab":
|
||||
m.activeTab = (m.activeTab - 1 + 3) % 3
|
||||
*m.activeTabP = m.activeTab
|
||||
m.applyFilter()
|
||||
m.updateTitle()
|
||||
skipGroupItem(&m.list, 1)
|
||||
@@ -546,7 +564,7 @@ func (m listTUIModel) View() string {
|
||||
|
||||
// Loading state — spinner + message
|
||||
if m.loading {
|
||||
return fmt.Sprintf("\n %s Loading skills...\n", m.loadSpinner.View())
|
||||
return fmt.Sprintf("\n %s Loading %s...\n", m.loadSpinner.View(), m.activeTab.noun())
|
||||
}
|
||||
|
||||
// Content viewer — dual-pane
|
||||
@@ -1005,6 +1023,14 @@ func renderDetailParagraph(lines []string) []string {
|
||||
|
||||
func detailStatusBits(e skillEntry) string {
|
||||
var bits []string
|
||||
|
||||
// Kind label (Agent / Skill)
|
||||
if e.Kind == "agent" {
|
||||
bits = append(bits, tc.Cyan.Render("Agent"))
|
||||
} else {
|
||||
bits = append(bits, tc.Cyan.Render("Skill"))
|
||||
}
|
||||
|
||||
switch {
|
||||
case e.RepoName != "":
|
||||
bits = append(bits, tc.Green.Render("tracked"))
|
||||
|
||||
@@ -27,7 +27,10 @@ func (g groupItem) Title() string { return g.label }
|
||||
func (g groupItem) Description() string { return "" }
|
||||
|
||||
// listSkillDelegate renders a compact single-line browser row for the list TUI.
|
||||
type listSkillDelegate struct{}
|
||||
// activeTab is a shared pointer so the delegate sees tab changes without re-creation.
|
||||
type listSkillDelegate struct {
|
||||
activeTab *listTab // nil-safe: treat nil as listTabAll
|
||||
}
|
||||
|
||||
func (listSkillDelegate) Height() int { return 1 }
|
||||
func (listSkillDelegate) Spacing() int { return 0 }
|
||||
@@ -35,7 +38,7 @@ func (listSkillDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (listSkillDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
|
||||
func (d listSkillDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
|
||||
width := m.Width()
|
||||
if width <= 0 {
|
||||
width = 40
|
||||
@@ -46,7 +49,8 @@ func (listSkillDelegate) Render(w io.Writer, m list.Model, index int, item list.
|
||||
renderGroupRow(w, v, width)
|
||||
case skillItem:
|
||||
selected := index == m.Index()
|
||||
renderSkillRow(w, v, width, selected)
|
||||
allTab := d.activeTab != nil && *d.activeTab == listTabAll
|
||||
renderSkillRow(w, v, width, selected, allTab)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +70,8 @@ func renderGroupRow(w io.Writer, g groupItem, width int) {
|
||||
fmt.Fprint(w, tc.Dim.Render("─ ")+label+" "+tc.Dim.Render(line))
|
||||
}
|
||||
|
||||
func renderSkillRow(w io.Writer, skill skillItem, width int, selected bool) {
|
||||
renderPrefixRow(w, skillTitleLine(skill.entry), width, selected)
|
||||
func renderSkillRow(w io.Writer, skill skillItem, width int, selected bool, allTab bool) {
|
||||
renderPrefixRow(w, skillTitleLine(skill.entry, allTab), width, selected)
|
||||
}
|
||||
|
||||
// renderPrefixRow renders a single-line list row with a "▌" prefix bar.
|
||||
@@ -201,14 +205,18 @@ func (i skillItem) Description() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func skillTitleLine(e skillEntry) string {
|
||||
func skillTitleLine(e skillEntry, allTab bool) string {
|
||||
if e.Disabled {
|
||||
// Disabled: dim the entire name + ⊘ prefix
|
||||
return tc.Dim.Render("⊘ " + compactSkillPath(e))
|
||||
}
|
||||
var prefix string
|
||||
if e.Kind == "agent" {
|
||||
prefix = tc.Cyan.Render("[A]") + " "
|
||||
if allTab {
|
||||
if e.Kind == "agent" {
|
||||
prefix = tc.Cyan.Render("[A]") + " "
|
||||
} else {
|
||||
prefix = tc.Cyan.Render("[S]") + " "
|
||||
}
|
||||
}
|
||||
title := prefix + colorSkillPath(compactSkillPath(e))
|
||||
if badge := skillTypeBadge(e); badge != "" {
|
||||
@@ -325,13 +333,16 @@ func toSkillItems(entries []skillEntry) []skillItem {
|
||||
// buildGroupedItems inserts groupItem separators before each repo/local group.
|
||||
// Skills must be sorted by RelPath (tracked repos with "_" prefix sort first).
|
||||
// If all skills belong to a single group (e.g. all standalone), no separators are added.
|
||||
// When items contain mixed kinds (skills + agents), groups are keyed by kind+repo
|
||||
// so skills and agents stay in separate blocks.
|
||||
func buildGroupedItems(skills []skillItem) []list.Item {
|
||||
// Check if there are multiple groups.
|
||||
groups := map[string]bool{}
|
||||
hasMultiKinds := false
|
||||
for _, s := range skills {
|
||||
groups[s.entry.RepoName] = true
|
||||
if len(groups) > 1 {
|
||||
break
|
||||
groups[s.entry.Kind+"\x00"+s.entry.RepoName] = true
|
||||
if !hasMultiKinds && len(skills) > 0 && s.entry.Kind != skills[0].entry.Kind {
|
||||
hasMultiKinds = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,12 +372,20 @@ func buildGroupedItems(skills []skillItem) []list.Item {
|
||||
}
|
||||
|
||||
for _, s := range skills {
|
||||
key := s.entry.RepoName // "" for local
|
||||
key := s.entry.Kind + "\x00" + s.entry.RepoName
|
||||
if key != currentGroup {
|
||||
flush()
|
||||
label := "standalone"
|
||||
if key != "" {
|
||||
label = strings.TrimPrefix(key, "_")
|
||||
if s.entry.RepoName != "" {
|
||||
label = strings.TrimPrefix(s.entry.RepoName, "_")
|
||||
}
|
||||
// Prefix with kind when mixed to visually separate skills/agents
|
||||
if hasMultiKinds {
|
||||
kindPrefix := "Skills"
|
||||
if s.entry.Kind == "agent" {
|
||||
kindPrefix = "Agents"
|
||||
}
|
||||
label = kindPrefix + " · " + label
|
||||
}
|
||||
items = append(items, groupItem{label: label})
|
||||
currentGroup = key
|
||||
|
||||
Reference in New Issue
Block a user