Charm-based CLI with JSON persistence, status/list filters, external editor editing, command-history undo/redo, and glamour markdown without AutoStyle OSC hangs. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package config
|
|
|
|
import "path/filepath"
|
|
|
|
const (
|
|
AppName = "task-master"
|
|
DefaultProject = "inbox"
|
|
DefaultTheme = "default"
|
|
configFileName = "config.json"
|
|
)
|
|
|
|
// Config holds application settings persisted under ~/.config/task-master.
|
|
type Config struct {
|
|
ActiveProject string `json:"activeProject"`
|
|
DataDir string `json:"dataDir"`
|
|
Theme string `json:"theme"`
|
|
// ProjectLists maps project ID → board list id (all|backlog|in_progress|done).
|
|
ProjectLists map[string]string `json:"projectLists,omitempty"`
|
|
}
|
|
|
|
// Path returns the absolute path to the config file.
|
|
func Path(home string) string {
|
|
return filepath.Join(home, ".config", AppName, configFileName)
|
|
}
|
|
|
|
// DefaultDataDir returns the default data directory under ~/.local/share.
|
|
func DefaultDataDir(home string) string {
|
|
return filepath.Join(home, ".local", "share", AppName)
|
|
}
|
|
|
|
// Defaults returns a Config with sensible defaults for the given home directory.
|
|
func Defaults(home string) Config {
|
|
return Config{
|
|
ActiveProject: DefaultProject,
|
|
DataDir: DefaultDataDir(home),
|
|
Theme: DefaultTheme,
|
|
ProjectLists: map[string]string{},
|
|
}
|
|
}
|
|
|
|
// ApplyDefaults fills empty fields from defaults without overwriting set values.
|
|
func (c *Config) ApplyDefaults(home string) {
|
|
d := Defaults(home)
|
|
if c.ActiveProject == "" {
|
|
c.ActiveProject = d.ActiveProject
|
|
}
|
|
if c.DataDir == "" {
|
|
c.DataDir = d.DataDir
|
|
}
|
|
if c.Theme == "" {
|
|
c.Theme = d.Theme
|
|
}
|
|
if c.ProjectLists == nil {
|
|
c.ProjectLists = map[string]string{}
|
|
}
|
|
}
|
|
|
|
// ActiveBoardList returns the persisted board list for a project (default: all).
|
|
func (c *Config) ActiveBoardList(projectID string) string {
|
|
if c.ProjectLists == nil {
|
|
return "all"
|
|
}
|
|
if v, ok := c.ProjectLists[projectID]; ok && v != "" {
|
|
return v
|
|
}
|
|
return "all"
|
|
}
|
|
|
|
// SetActiveBoardList stores the board list for a project.
|
|
func (c *Config) SetActiveBoardList(projectID, listID string) {
|
|
if c.ProjectLists == nil {
|
|
c.ProjectLists = map[string]string{}
|
|
}
|
|
c.ProjectLists[projectID] = listID
|
|
}
|