Skip to content

Commit

Permalink
✨ Implement manifest: message (Closes #22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed Jul 9, 2021
1 parent a3aded6 commit 9ee2a4e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
31 changes: 30 additions & 1 deletion manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import (
"regexp"
"strings"

"github.com/charmbracelet/glamour"
"gopkg.in/yaml.v2"
)

type Variant struct {
// Properties exclusive to variants
Name string
Message string

// Properties that modify the "default variant"
Config Config
UserChrome FileTemplate `yaml:"userChrome"`
UserContent FileTemplate `yaml:"userContent"`
UserJS FileTemplate `yaml:"user.js"`
Assets []FileTemplate
Description string
Name string
}

type Manifest struct {
Expand All @@ -27,12 +32,15 @@ type Manifest struct {
FfcssVersion int `yaml:"ffcss"`
Variants map[string]Variant
OSNames map[string]string `yaml:"os"`

// Those can be modified by variant
CopyFrom string `yaml:"copy from"`
Config Config
UserChrome FileTemplate `yaml:"userChrome"`
UserContent FileTemplate `yaml:"userContent"`
UserJS FileTemplate `yaml:"user.js"`
Assets []FileTemplate
Message string
}

func (m Manifest) Name() string {
Expand Down Expand Up @@ -112,6 +120,9 @@ func (m Manifest) WithVariant(variant Variant) Manifest {
if variant.UserJS != "" {
newManifest.UserJS = variant.UserJS
}
if variant.Message != "" {
newManifest.Message = variant.Message
}
if len(variant.Assets) > 0 {
newManifest.Assets = variant.Assets
}
Expand Down Expand Up @@ -155,3 +166,21 @@ func (m Manifest) AvailableVariants() []string {
}
return names
}

// ShowMessage renders the message and prints it to the user
func (m Manifest) ShowMessage() error {
scheme := os.Getenv("COLORSCHEME")
if scheme != "light" && scheme != "dark" {
// TODO: detect with the terminal's current background color as a fallback
scheme = "dark"
}
rendered, err := glamour.Render(m.Message, scheme)
if err != nil {
return fmt.Errorf("while rendering message: %w", err)
}

if strings.TrimSpace(rendered) != "" {
fmt.Println(rendered)
}
return nil
}
4 changes: 2 additions & 2 deletions manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func TestAssetsPaths(t *testing.T) {
},
Assets: []string{"./{{ os }}/userChrome__{{ variant }}.css"}, // for the purposes of testing
OSNames: map[string]string{
"linux": "Linux",
"macos": "Linux",
"linux": "Linux",
"macos": "Linux",
"windows": "Windows",
},
}
Expand Down
7 changes: 7 additions & 0 deletions use.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func RunCommandUse(args docopt.Opts) error {
if err != nil {
return fmt.Errorf("couldn't install assets: %w", err)
}

// Show message
err = manifest.ShowMessage()
if err != nil {
return fmt.Errorf("couldn't display the message: %w", err)
}

}
return nil
}

0 comments on commit 9ee2a4e

Please sign in to comment.