better CLI and fixes

This commit is contained in:
Vojtěch Fošnár 2023-02-20 11:11:24 +01:00
parent 7bf795b455
commit 1d710c0356
No known key found for this signature in database
GPG key ID: 657727E71C40859A
2 changed files with 21 additions and 4 deletions

View file

@ -7,7 +7,7 @@ import (
"oss.terrastruct.com/d2/d2themes" "oss.terrastruct.com/d2/d2themes"
) )
var Catalog = []d2themes.Theme{ var LightCatalog = []d2themes.Theme{
NeutralDefault, NeutralDefault,
NeutralGrey, NeutralGrey,
FlagshipTerrastruct, FlagshipTerrastruct,
@ -22,11 +22,20 @@ var Catalog = []d2themes.Theme{
EarthTones, EarthTones,
EvergladeGreen, EvergladeGreen,
ButteredToast, ButteredToast,
}
var DarkCatalog = []d2themes.Theme{
DarkMauve, DarkMauve,
} }
func Find(id int64) d2themes.Theme { func Find(id int64) d2themes.Theme {
for _, theme := range Catalog { for _, theme := range LightCatalog {
if theme.ID == id {
return theme
}
}
for _, theme := range DarkCatalog {
if theme.ID == id { if theme.ID == id {
return theme return theme
} }
@ -37,8 +46,16 @@ func Find(id int64) d2themes.Theme {
func CLIString() string { func CLIString() string {
var s strings.Builder var s strings.Builder
for _, t := range Catalog {
s.WriteString("Light:\n")
for _, t := range LightCatalog {
s.WriteString(fmt.Sprintf("- %s: %d\n", t.Name, t.ID)) s.WriteString(fmt.Sprintf("- %s: %d\n", t.Name, t.ID))
} }
s.WriteString("Dark:\n")
for _, t := range DarkCatalog {
s.WriteString(fmt.Sprintf("- %s: %d\n", t.Name, t.ID))
}
return s.String() return s.String()
} }

View file

@ -68,7 +68,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
if err != nil { if err != nil {
return err return err
} }
darkThemeFlag, err := ms.Opts.Int64("D2_D_THEME", "dark_theme", "", -1, "the diagram dark theme ID. When left unset only the theme will be applied") darkThemeFlag, err := ms.Opts.Int64("D2_D_THEME", "dark-theme", "", -1, "the diagram dark theme ID. When left unset only the theme will be applied")
if err != nil { if err != nil {
return err return err
} }