1package ui23import (4 "src.rest/cat/012/internal/config"5)67// The theme picker is package themepicker; the model draws, keeps and8// saves the themes it picks.910// keepTheme makes name the theme and saves it in the config file. When11// the config picks a theme by the terminal's background, only the one12// for the current background changes.13func (m *Model) keepTheme(name string) {14 m.closeOverlay()15 m.prefs.preview = ""16 choice := m.prefs.Config.Theme()17 if choice.Light != choice.Dark && !m.prefs.light {18 choice.Dark = name19 } else if choice.Light != choice.Dark {20 choice.Light = name21 } else {22 choice = config.ThemeChoice{Light: name, Dark: name}23 }24 c := m.prefs.Config25 if c == nil {26 c = config.Load("", nil, nil)27 m.prefs.Config = c28 }29 // Until the next start, the choice wins over the file, the30 // environment and flags alike.31 was := c.Get("theme").Src32 c.Override("theme", choice.String(), "File > Settings > Theme")33 if p := m.applyTheme(); p != "" {34 m.note = m.th.Warning.Render(p)35 return36 }37 if c.Path == "" {38 m.note = "Theme " + name + " (not saved: no config file)"39 return40 }41 if err := config.SetInFile(c.Path, "theme", choice.String()); err != nil {42 m.fail("Couldn't save the theme: " + err.Error())43 return44 }45 m.note = "Theme " + name + ", saved in " + config.Tilde(c.Path)46 if was.Kind == config.FromEnv || was.Kind == config.FromFlag {47 m.note += " (" + was.String() + " overrides it at startup)"48 }49}