SaveThemeToUserConfig persists the theme reference to the user config file. If themeRef equals DefaultThemeRef, the setting is cleared (empty string).
(themeRef string)
| 483 | // SaveThemeToUserConfig persists the theme reference to the user config file. |
| 484 | // If themeRef equals DefaultThemeRef, the setting is cleared (empty string). |
| 485 | func SaveThemeToUserConfig(themeRef string) error { |
| 486 | cfg, err := userconfig.Load() |
| 487 | if err != nil { |
| 488 | return fmt.Errorf("loading user config: %w", err) |
| 489 | } |
| 490 | |
| 491 | if cfg.Settings == nil { |
| 492 | cfg.Settings = &userconfig.Settings{} |
| 493 | } |
| 494 | |
| 495 | // Clear the setting if using the default theme |
| 496 | if themeRef == DefaultThemeRef { |
| 497 | cfg.Settings.Theme = "" |
| 498 | } else { |
| 499 | cfg.Settings.Theme = themeRef |
| 500 | } |
| 501 | |
| 502 | if err := cfg.Save(); err != nil { |
| 503 | return fmt.Errorf("saving user config: %w", err) |
| 504 | } |
| 505 | |
| 506 | return nil |
| 507 | } |
| 508 | |
| 509 | // GetPersistedThemeRef returns the theme reference persisted in user config. |
| 510 | // Returns DefaultThemeRef if no theme is set or if loading fails. |
no test coverage detected