package internal import ( "fmt" "os" "path/filepath" "charm.land/lipgloss/v2" "u-tabs/internal/style" ) // Workspace 工作空间定义 type Workspace struct { Index int // 全局索引 N int // 编号 Title string // 短名 Prompt string // 描述 Tech string // 技术栈 Deploy string // 部署情况 Dir string // 目录路径 Group string // 分组标签 } // Group 分组定义 type Group struct { Label string Desc string } // 运行时数据 var Groups []Group var AllWorkspaces []Workspace var wsByNum map[int]*Workspace // NoConfig 配置文件不存在标记 var NoConfig bool func InitData() { cfg, err := LoadConfig() if err != nil { NoConfig = true home, _ := os.UserHomeDir() Groups = []Group{{Label: "HOME", Desc: "默认"}} AllWorkspaces = []Workspace{ {Index: 0, N: 0, Title: "home", Prompt: "用户主目录", Tech: "-", Deploy: "本地", Dir: home, Group: "HOME"}, } wsByNum = map[int]*Workspace{0: &AllWorkspaces[0]} return } Groups, AllWorkspaces = cfg.ToInternal() wsByNum = make(map[int]*Workspace, len(AllWorkspaces)) for i := range AllWorkspaces { wsByNum[AllWorkspaces[i].N] = &AllWorkspaces[i] } } func WorkspacesByGroup(groupLabel string) []Workspace { var result []Workspace for _, ws := range AllWorkspaces { if ws.Group == groupLabel { result = append(result, ws) } } return result } func FindByNumber(n int) *Workspace { return wsByNum[n] } // ConfigHint 配置文件提示文案 func ConfigHint() string { if !NoConfig { return "" } home, _ := os.UserHomeDir() path := filepath.Join(home, ".u-tabs", "config.yaml") return lipgloss.NewStyle().Foreground(style.Warning).Bold(true).Render( fmt.Sprintf(" ⚠ 未找到配置文件,请创建: %s (参考 config.example.yaml)", path)) }