-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split theme package to move themes outside of the UI. This allows other parts of the app which are not part of the UI to use these themes. A colour package was added to act as a link between UI styles and the theme package.
- Loading branch information
1 parent
fcc9b23
commit 0d23778
Showing
34 changed files
with
390 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package theme | ||
|
||
import ( | ||
"os" | ||
|
||
tint "github.com/lrstanley/bubbletint" | ||
"github.com/mikelorant/committed/internal/config" | ||
"github.com/muesli/termenv" | ||
) | ||
|
||
type Theme struct { | ||
ID string | ||
Registry *tint.Registry | ||
} | ||
|
||
func New(clr config.Colour) Theme { | ||
ts := tints(clr) | ||
reg := tint.NewRegistry(ts[0], ts[1:]...) | ||
|
||
return Theme{ | ||
ID: reg.ID(), | ||
Registry: reg, | ||
} | ||
} | ||
|
||
func (t *Theme) Next() { | ||
ids := t.List() | ||
l := len(t.List()) | ||
|
||
switch { | ||
case t.ID == ids[l-1]: | ||
t.Set(ids[0]) | ||
default: | ||
t.Registry.NextTint() | ||
} | ||
|
||
t.ID = t.Registry.ID() | ||
} | ||
|
||
func (t *Theme) Set(id string) bool { | ||
if ok := t.Registry.SetTintID(id); !ok { | ||
return false | ||
} | ||
|
||
t.ID = id | ||
|
||
return true | ||
} | ||
|
||
func (t *Theme) List() []string { | ||
var ts []string | ||
|
||
for _, t := range t.Registry.Tints() { | ||
ts = append(ts, t.ID()) | ||
} | ||
|
||
return ts | ||
} | ||
|
||
func tints(clr config.Colour) []tint.Tint { | ||
if clr == config.ColourDark { | ||
return dark() | ||
} | ||
|
||
if clr == config.ColourLight { | ||
return light() | ||
} | ||
|
||
if termenv.NewOutput(os.Stdout).HasDarkBackground() { | ||
return dark() | ||
} | ||
|
||
return light() | ||
} | ||
|
||
func dark() []tint.Tint { | ||
return []tint.Tint{ | ||
tint.TintBuiltinDark, | ||
tint.TintGruvboxDark, | ||
tint.TintSolarizedDarkHigherContrast, | ||
tint.TintRetrowave, | ||
tint.TintDracula, | ||
tint.TintNord, | ||
tint.TintTokyoNight, | ||
} | ||
} | ||
|
||
func light() []tint.Tint { | ||
return []tint.Tint{ | ||
tint.TintBuiltinLight, | ||
tint.TintGruvboxLight, | ||
tint.TintBuiltinSolarizedLight, | ||
tint.TintBuiltinTangoLight, | ||
tint.TintTokyoNightLight, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.