1package shell
2
3import (
4 "log/slog"
5 "sync"
6)
7
8// PersistentShell is a singleton shell instance that maintains state across the application
9type PersistentShell struct {
10 *Shell
11}
12
13var (
14 once sync.Once
15 shellInstance *PersistentShell
16)
17
18// GetPersistentShell returns the singleton persistent shell instance
19// This maintains backward compatibility with the existing API
20func GetPersistentShell(cwd string) *PersistentShell {
21 once.Do(func() {
22 shellInstance = &PersistentShell{
23 Shell: NewShell(&Options{
24 WorkingDir: cwd,
25 Logger: &loggingAdapter{},
26 }),
27 }
28 })
29 return shellInstance
30}
31
32// slog.dapter adapts the internal slog.package to the Logger interface
33type loggingAdapter struct{}
34
35func (l *loggingAdapter) InfoPersist(msg string, keysAndValues ...any) {
36 slog.Info(msg, keysAndValues...)
37}