Skip to content

Commit

Permalink
Merge pull request #107 from mattn/windows
Browse files Browse the repository at this point in the history
Support Windows colors
  • Loading branch information
koddr authored Oct 19, 2021
2 parents 3bb3601 + bcacd0a commit dd12085
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd

import (
"github.com/AlecAivazis/survey/v2"
"github.com/create-go-app/cli/v3/pkg/cgapp"
"github.com/create-go-app/cli/v3/pkg/registry"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -48,6 +49,11 @@ frontend (JavaScript, TypeScript) and deploy automation
A helpful documentation and next steps -> https://create-go.app/`,
}

func init() {
rootCmd.SetOut(cgapp.Stdout)
rootCmd.SetErr(cgapp.Stderr)
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand Down
12 changes: 9 additions & 3 deletions pkg/cgapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ package cgapp
import (
"fmt"
"time"

"github.com/mattn/go-colorable"
)

var (
Stdout = colorable.NewColorableStdout()
Stderr = colorable.NewColorableStderr()
)

// ShowMessage function for send message to output.
func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) {
// Define variables.
var startLine, endLine string
Expand All @@ -22,12 +28,12 @@ func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) {
endLine = "\n" // set a new line
}

fmt.Println(startLine + colorizeLevel(level) + text + endLine)
fmt.Fprintln(Stdout, startLine+colorizeLevel(level)+text+endLine)
}

// ShowError function for send error message to output.
func ShowError(text string) error {
return fmt.Errorf(colorizeLevel("error") + text)
return fmt.Errorf("%s", colorizeLevel("error")+text)
}

// CalculateDurationTime func to calculate duration time.
Expand Down

0 comments on commit dd12085

Please sign in to comment.