-
Notifications
You must be signed in to change notification settings - Fork 12
Add theme to lets settings
#353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,23 +5,27 @@ import ( | |
| "os" | ||
|
|
||
| "github.com/fatih/color" | ||
| "github.com/lets-cli/lets/internal/theme" | ||
| "github.com/lets-cli/lets/internal/util" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| type FileSettings struct { | ||
| NoColor *bool `yaml:"no_color"` | ||
| UpgradeNotify *bool `yaml:"upgrade_notify"` | ||
| NoColor *bool `yaml:"no_color"` | ||
| Theme *string `yaml:"theme"` | ||
| UpgradeNotify *bool `yaml:"upgrade_notify"` | ||
| } | ||
|
|
||
| type Settings struct { | ||
| NoColor bool | ||
| Theme string | ||
| UpgradeNotify bool | ||
| } | ||
|
|
||
| func Default() Settings { | ||
| return Settings{ | ||
| NoColor: false, | ||
| Theme: theme.DefaultName, | ||
| UpgradeNotify: true, | ||
| } | ||
| } | ||
|
|
@@ -63,12 +67,26 @@ func LoadFile(path string) (Settings, error) { | |
| cfg.NoColor = *fileSettings.NoColor | ||
| } | ||
|
|
||
| if fileSettings.Theme != nil { | ||
| cfg.Theme = *fileSettings.Theme | ||
| } | ||
|
|
||
| if fileSettings.UpgradeNotify != nil { | ||
| cfg.UpgradeNotify = *fileSettings.UpgradeNotify | ||
| } | ||
|
|
||
| applyEnvOverrides(&cfg) | ||
|
|
||
| if !theme.ValidName(cfg.Theme) { | ||
| return Settings{}, fmt.Errorf( | ||
|
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Avoid hard-coding the list of valid themes in the error message to prevent drift from Right now the message hard-codes |
||
| "invalid theme %q: must be one of %q, %q, %q", | ||
| cfg.Theme, | ||
| theme.DefaultName, | ||
| theme.ANSIName, | ||
| theme.SynthwaveName, | ||
| ) | ||
| } | ||
|
|
||
| return cfg, nil | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package theme | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "charm.land/lipgloss/v2" | ||
| "github.com/charmbracelet/x/exp/charmtone" | ||
| ) | ||
|
|
||
| func TestValidName(t *testing.T) { | ||
| for _, name := range []string{DefaultName, ANSIName, SynthwaveName} { | ||
| if !ValidName(name) { | ||
| t.Fatalf("expected %q to be valid", name) | ||
| } | ||
| } | ||
|
|
||
| if ValidName("vaporwave") { | ||
| t.Fatal("expected unknown theme to be invalid") | ||
| } | ||
| } | ||
|
|
||
| func TestColorSchemeByName(t *testing.T) { | ||
| if got := ColorSchemeByName(DefaultName)(lipgloss.LightDark(true)).Title; got != charmtone.Ash { | ||
| t.Fatalf("expected default theme title color %v, got %v", charmtone.Ash, got) | ||
| } | ||
|
|
||
| if got := ColorSchemeByName(ANSIName)(lipgloss.LightDark(true)).ErrorDetails; got != lipgloss.Red { | ||
| t.Fatalf("expected ansi theme error details color %v, got %v", lipgloss.Red, got) | ||
| } | ||
|
|
||
| if got := ColorSchemeByName(SynthwaveName)(lipgloss.LightDark(true)).Title; got != charmtone.Grape { | ||
| t.Fatalf("expected synthwave theme title color %v, got %v", charmtone.Grape, got) | ||
| } | ||
|
|
||
| if got := ColorSchemeByName("unknown")(lipgloss.LightDark(true)).Title; got != charmtone.Ash { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Reduce coupling of the fallback behavior test to specific color values The last assertion hardcodes want := ColorSchemeByName(DefaultName)(lipgloss.LightDark(true))
got := ColorSchemeByName("unknown")(lipgloss.LightDark(true))
if got.Title != want.Title { /* ... */ }Possibly compare multiple fields to assert the fallback behavior without hardcoding specific colors. Suggested implementation: func TestColorSchemeByName(t *testing.T) {
lightDark := lipgloss.LightDark(true)
defaultScheme := ColorSchemeByName(DefaultName)(lightDark)
if defaultScheme.Title != charmtone.Ash {
t.Fatalf("expected default theme title color %v, got %v", charmtone.Ash, defaultScheme.Title)
}
unknownScheme := ColorSchemeByName("unknown")(lightDark)
if unknownScheme.Title != defaultScheme.Title {
t.Fatalf("expected unknown theme to fall back to default title color %v, got %v", defaultScheme.Title, unknownScheme.Title)
}
if unknownScheme.ErrorDetails != defaultScheme.ErrorDetails {
t.Fatalf("expected unknown theme to fall back to default error details color %v, got %v", defaultScheme.ErrorDetails, unknownScheme.ErrorDetails)
}
}If the |
||
| t.Fatalf("expected unknown theme to fall back to %v, got %v", charmtone.Ash, got) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Consider expanding the abbreviation "runtime env" to "runtime environment" for clarity.
Spelling this out (e.g., "Do not use this file for project commands or runtime environment.") will make the docs clearer to all readers.