@@ -4,8 +4,19 @@ import (
44 "sort"
55
66 "github.com/charmbracelet/lipgloss"
7+
8+ "os"
9+
10+ "path/filepath"
11+
12+ "github.com/BurntSushi/toml"
13+
14+ "fmt"
715)
816
17+ // DefaultThemeName is the name of the default theme.
18+ const DefaultThemeName = "GitHub Dark"
19+
920// Palette defines a set of colors for a theme.
1021type Palette struct {
1122 Black , Red , Green , Yellow , Blue , Magenta , Cyan , White ,
@@ -139,6 +150,20 @@ type TreeStyle struct {
139150 Connector , ConnectorLast , Prefix , PrefixLast string
140151}
141152
153+ //config.toml
154+ type themeConfig struct {
155+ Theme string `toml:"theme"`
156+ }
157+
158+ // custom_theme.toml
159+ type ThemeFile struct {
160+ Fg string `toml:"fg"`
161+ Bg string `toml:"bg"`
162+ Normal map [string ]string `toml:"normal"`
163+ Bright map [string ]string `toml:"bright"`
164+ Dark map [string ]string `toml:"dark"`
165+ }
166+
142167// Themes holds all the available themes, generated from palettes.
143168var Themes = map [string ]Theme {}
144169
@@ -216,3 +241,46 @@ func ThemeNames() []string {
216241 sort .Strings (names )
217242 return names
218243}
244+
245+ func load_config () (* themeConfig , error ){
246+ cfgPath := ConfigFilePath
247+
248+ var cfg themeConfig
249+ if _ , err := toml .DecodeFile (cfgPath , & cfg ); err != nil {
250+ return nil , err
251+ }
252+
253+ return & cfg , nil
254+ }
255+
256+ func load_custom_theme (name string ) (* Palette , error ){
257+ themePath := filepath .Join (ConfigThemesDirPath , name + ".toml" )
258+ if _ ,err := os .Stat (themePath ); os .IsNotExist (err ) {
259+ return nil , fmt .Errorf ("theme not found: %s" , name )
260+ }
261+
262+ var tf ThemeFile
263+ if _ , err := toml .DecodeFile (themePath , & tf ); err != nil {
264+ return nil , err
265+ }
266+
267+ // Create a Palette from the ThemeFile
268+ p := Palette {
269+ Fg : tf .Fg ,
270+ Bg : tf .Bg ,
271+ Black : tf .Normal ["Black" ], Red : tf .Normal ["Red" ], Green : tf .Normal ["Green" ], Yellow : tf .Normal ["Yellow" ],
272+ Blue : tf .Normal ["Blue" ], Magenta : tf .Normal ["Magenta" ], Cyan : tf .Normal ["Cyan" ], White : tf .Normal ["White" ],
273+
274+ BrightBlack : tf .Bright ["Black" ], BrightRed : tf .Bright ["Red" ], BrightGreen : tf .Bright ["Green" ], BrightYellow : tf .Bright ["Yellow" ],
275+ BrightBlue : tf .Bright ["Blue" ], BrightMagenta : tf .Bright ["Magenta" ], BrightCyan : tf .Bright ["Cyan" ], BrightWhite : tf .Bright ["White" ],
276+
277+ DarkBlack : tf .Dark ["Black" ], DarkRed : tf .Dark ["Red" ], DarkGreen : tf .Dark ["Green" ], DarkYellow : tf .Dark ["Yellow" ],
278+ DarkBlue : tf .Dark ["Blue" ], DarkMagenta : tf .Dark ["Magenta" ], DarkCyan : tf .Dark ["Cyan" ], DarkWhite : tf .Dark ["White" ],
279+
280+ }
281+
282+ Palettes [name ] = p // Add to Palettes map for future use
283+ Themes [name ] = NewThemeFromPalette (p ) // Add to Themes map
284+
285+ return & p , nil
286+ }
0 commit comments