on 142ff9e help sign in
crush/internal/shell/persistent.go
38 lines 889 B history raw
1package shell
3import (
4 "sync"
6 "github.com/charmbracelet/crush/internal/logging"
7)
9// PersistentShell is a singleton shell instance that maintains state across the application
10type PersistentShell struct {
11 *Shell
14var (
15 once sync.Once
16 shellInstance *PersistentShell
19// GetPersistentShell returns the singleton persistent shell instance
20// This maintains backward compatibility with the existing API
21func GetPersistentShell(cwd string) *PersistentShell {
22 once.Do(func() {
23 shellInstance = &PersistentShell{
24 Shell: NewShell(&Options{
25 WorkingDir: cwd,
26 Logger: &loggingAdapter{},
27 }),
28 }
29 })
30 return shellInstance
33// loggingAdapter adapts the internal logging package to the Logger interface
34type loggingAdapter struct{}
36func (l *loggingAdapter) InfoPersist(msg string, keysAndValues ...interface{}) {
37 logging.InfoPersist(msg, keysAndValues...)