persistent.go 889 B

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