From 7fcb537f850770e24ddb262bf9723bc06412186f Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Thu, 20 Oct 2022 06:11:20 -0400 Subject: [PATCH] feature/turn off color terminal output of dev command (#1947) * feat: Adds option to dev command to turn off color terminal output * Update docs Co-authored-by: Lea Anthony --- v2/cmd/wails/internal/commands/dev/dev.go | 6 +++ v2/internal/colour/colour.go | 56 +++++++++++++++++++++++ website/docs/reference/cli.mdx | 3 +- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index 0614926fa..d61bc1c7c 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -93,6 +93,7 @@ type devFlags struct { frontendDevServerURL string skipFrontend bool + noColour bool } // AddSubcommand adds the `dev` command for the Wails application @@ -108,6 +109,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { command.StringFlag("reloaddirs", "Additional directories to trigger reloads (comma separated)", &flags.reloadDirs) command.BoolFlag("browser", "Open application in browser", &flags.openBrowser) command.BoolFlag("noreload", "Disable reload on asset change", &flags.noReload) + command.BoolFlag("nocolour", "Turn off colour cli output", &flags.noColour) command.BoolFlag("skipbindings", "Skip bindings generation", &flags.skipBindings) command.StringFlag("wailsjsdir", "Directory to generate the Wails JS modules", &flags.wailsjsdir) command.StringFlag("tags", "Build tags to pass to Go compiler. Must be quoted. Space or comma (but not both) separated", &flags.tags) @@ -123,6 +125,10 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { command.BoolFlag("s", "Skips building the frontend", &flags.skipFrontend) command.Action(func() error { + if flags.noColour { + colour.ColourEnabled = false + } + // Create logger logger := clilogger.New(w) app.PrintBanner() diff --git a/v2/internal/colour/colour.go b/v2/internal/colour/colour.go index a81345533..ee1ca9743 100644 --- a/v2/internal/colour/colour.go +++ b/v2/internal/colour/colour.go @@ -7,77 +7,133 @@ import ( "github.com/wzshiming/ctc" ) +var ColourEnabled = true + func Col(col ctc.Color, text string) string { + if !ColourEnabled { + return text + } return fmt.Sprintf("%s%s%s", col, text, ctc.Reset) } func Yellow(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightYellow, text) } func Red(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightRed, text) } func Blue(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightBlue, text) } func Green(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightGreen, text) } func Cyan(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightCyan, text) } func Magenta(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightMagenta, text) } func White(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightWhite, text) } func Black(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBrightBlack, text) } func DarkYellow(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundYellow, text) } func DarkRed(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundRed, text) } func DarkBlue(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBlue, text) } func DarkGreen(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundGreen, text) } func DarkCyan(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundCyan, text) } func DarkMagenta(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundMagenta, text) } func DarkWhite(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundWhite, text) } func DarkBlack(text string) string { + if !ColourEnabled { + return text + } return Col(ctc.ForegroundBlack, text) } var rainbowCols = []func(string) string{Red, Yellow, Green, Cyan, Blue, Magenta} func Rainbow(text string) string { + if !ColourEnabled { + return text + } var builder strings.Builder for i := 0; i < len(text); i++ { diff --git a/website/docs/reference/cli.mdx b/website/docs/reference/cli.mdx index 8f3577e74..1180558ef 100644 --- a/website/docs/reference/cli.mdx +++ b/website/docs/reference/cli.mdx @@ -167,7 +167,7 @@ Your system is ready for Wails development! - On macOS, it will bundle the application into a `.app` file and run it. It will use a `build/darwin/Info.dev.plist` for development. | Flag | Description | Default | -| :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- | +|:-----------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------| | -assetdir "./path/to/assets" | Serve assets from the given directory instead of using the provided asset FS | Value in `wails.json` | | -browser | Opens a browser to `http://localhost:34115` on startup | | | -compiler "compiler" | Use a different go compiler to build, eg go1.15beta1 | go | @@ -177,6 +177,7 @@ Your system is ready for Wails development! | -tags "extra tags" | Build tags to pass to compiler (quoted and space separated) | | | -loglevel "loglevel" | Loglevel to use - Trace, Debug, Info, Warning, Error | Debug | | -noreload | Disable automatic reload when assets change | | +| -nocolour | Turn off colour cli output | false | | -nogen | Disable generate module | | | -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 | | -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` |