-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.go
More file actions
76 lines (66 loc) · 2.14 KB
/
Copy pathwidget.go
File metadata and controls
76 lines (66 loc) · 2.14 KB
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
package widgets
import (
"bytes"
"os"
"os/exec"
"sync"
"github.com/yuys13/agystatusline/types"
"github.com/yuys13/agystatusline/utils"
)
// Widget defines the interface that all statusline widgets must implement.
type Widget interface {
GetDefaultColor() string
GetDisplayName() string
Render(item types.WidgetItem, ctx types.RenderContext, settings types.Settings) (title string, body string, err error)
GetBodyColor(item types.WidgetItem, ctx types.RenderContext) string
}
type CwdResolver = utils.CwdResolver
var (
registry = make(map[string]Widget)
regMutex sync.RWMutex
)
// RegisterWidget registers a widget with the global registry.
func RegisterWidget(name string, w Widget) {
regMutex.Lock()
defer regMutex.Unlock()
registry[name] = w
}
// GetWidget retrieves a widget by name from the registry.
func GetWidget(name string) Widget {
regMutex.RLock()
defer regMutex.RUnlock()
return registry[name]
}
// runGitExec runs a real git command on the OS.
func runGitExec(args []string, cwd string) (string, error) {
cmd := exec.Command("git", args...)
cmd.Dir = cwd
cmd.Env = append(os.Environ(), "GIT_OPTIONAL_LOCKS=0")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return "", err
}
return stdout.String(), nil
}
// runGitCommand wraps utils.RunGit to execute commands with cache.
var runGitCommand = func(command string, ctx CwdResolver, ttlSeconds int) (string, error) {
return utils.RunGit(command, ctx, ttlSeconds, runGitExec)
}
// RegisterAll registers all available widget implementations.
func RegisterAll() {
RegisterWidget("model", &ModelWidget{})
RegisterWidget("git-branch", &GitBranchWidget{})
RegisterWidget("git-changes", &GitChangesWidget{})
RegisterWidget("quota", &QuotaWidget{})
RegisterWidget("custom-text", &CustomTextWidget{})
RegisterWidget("sandbox", &SandboxWidget{})
RegisterWidget("agent-state", &AgentStateWidget{})
RegisterWidget("context-bar", &ContextBarWidget{})
RegisterWidget("quota-bar", &QuotaBarWidget{})
RegisterWidget("artifacts", &ArtifactsWidget{})
RegisterWidget("subagents", &SubagentsWidget{})
RegisterWidget("tasks", &TasksWidget{})
}