5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 07:21:32 +08:00

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 <lea.anthony@gmail.com>
This commit is contained in:
Scott Opell 2022-10-20 06:11:20 -04:00 committed by GitHub
parent 8b07a0f582
commit 7fcb537f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 1 deletions

View File

@ -93,6 +93,7 @@ type devFlags struct {
frontendDevServerURL string frontendDevServerURL string
skipFrontend bool skipFrontend bool
noColour bool
} }
// AddSubcommand adds the `dev` command for the Wails application // 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.StringFlag("reloaddirs", "Additional directories to trigger reloads (comma separated)", &flags.reloadDirs)
command.BoolFlag("browser", "Open application in browser", &flags.openBrowser) command.BoolFlag("browser", "Open application in browser", &flags.openBrowser)
command.BoolFlag("noreload", "Disable reload on asset change", &flags.noReload) 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.BoolFlag("skipbindings", "Skip bindings generation", &flags.skipBindings)
command.StringFlag("wailsjsdir", "Directory to generate the Wails JS modules", &flags.wailsjsdir) 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) 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.BoolFlag("s", "Skips building the frontend", &flags.skipFrontend)
command.Action(func() error { command.Action(func() error {
if flags.noColour {
colour.ColourEnabled = false
}
// Create logger // Create logger
logger := clilogger.New(w) logger := clilogger.New(w)
app.PrintBanner() app.PrintBanner()

View File

@ -7,77 +7,133 @@ import (
"github.com/wzshiming/ctc" "github.com/wzshiming/ctc"
) )
var ColourEnabled = true
func Col(col ctc.Color, text string) string { func Col(col ctc.Color, text string) string {
if !ColourEnabled {
return text
}
return fmt.Sprintf("%s%s%s", col, text, ctc.Reset) return fmt.Sprintf("%s%s%s", col, text, ctc.Reset)
} }
func Yellow(text string) string { func Yellow(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightYellow, text) return Col(ctc.ForegroundBrightYellow, text)
} }
func Red(text string) string { func Red(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightRed, text) return Col(ctc.ForegroundBrightRed, text)
} }
func Blue(text string) string { func Blue(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightBlue, text) return Col(ctc.ForegroundBrightBlue, text)
} }
func Green(text string) string { func Green(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightGreen, text) return Col(ctc.ForegroundBrightGreen, text)
} }
func Cyan(text string) string { func Cyan(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightCyan, text) return Col(ctc.ForegroundBrightCyan, text)
} }
func Magenta(text string) string { func Magenta(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightMagenta, text) return Col(ctc.ForegroundBrightMagenta, text)
} }
func White(text string) string { func White(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightWhite, text) return Col(ctc.ForegroundBrightWhite, text)
} }
func Black(text string) string { func Black(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBrightBlack, text) return Col(ctc.ForegroundBrightBlack, text)
} }
func DarkYellow(text string) string { func DarkYellow(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundYellow, text) return Col(ctc.ForegroundYellow, text)
} }
func DarkRed(text string) string { func DarkRed(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundRed, text) return Col(ctc.ForegroundRed, text)
} }
func DarkBlue(text string) string { func DarkBlue(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBlue, text) return Col(ctc.ForegroundBlue, text)
} }
func DarkGreen(text string) string { func DarkGreen(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundGreen, text) return Col(ctc.ForegroundGreen, text)
} }
func DarkCyan(text string) string { func DarkCyan(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundCyan, text) return Col(ctc.ForegroundCyan, text)
} }
func DarkMagenta(text string) string { func DarkMagenta(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundMagenta, text) return Col(ctc.ForegroundMagenta, text)
} }
func DarkWhite(text string) string { func DarkWhite(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundWhite, text) return Col(ctc.ForegroundWhite, text)
} }
func DarkBlack(text string) string { func DarkBlack(text string) string {
if !ColourEnabled {
return text
}
return Col(ctc.ForegroundBlack, text) return Col(ctc.ForegroundBlack, text)
} }
var rainbowCols = []func(string) string{Red, Yellow, Green, Cyan, Blue, Magenta} var rainbowCols = []func(string) string{Red, Yellow, Green, Cyan, Blue, Magenta}
func Rainbow(text string) string { func Rainbow(text string) string {
if !ColourEnabled {
return text
}
var builder strings.Builder var builder strings.Builder
for i := 0; i < len(text); i++ { for i := 0; i < len(text); i++ {

View File

@ -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. - 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 | | Flag | Description | Default |
| :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- | |:-----------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------|
| -assetdir "./path/to/assets" | Serve assets from the given directory instead of using the provided asset FS | Value in `wails.json` | | -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 | | | -browser | Opens a browser to `http://localhost:34115` on startup | |
| -compiler "compiler" | Use a different go compiler to build, eg go1.15beta1 | go | | -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) | | | -tags "extra tags" | Build tags to pass to compiler (quoted and space separated) | |
| -loglevel "loglevel" | Loglevel to use - Trace, Debug, Info, Warning, Error | Debug | | -loglevel "loglevel" | Loglevel to use - Trace, Debug, Info, Warning, Error | Debug |
| -noreload | Disable automatic reload when assets change | | | -noreload | Disable automatic reload when assets change | |
| -nocolour | Turn off colour cli output | false |
| -nogen | Disable generate module | | | -nogen | Disable generate module | |
| -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 | | -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 |
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` | | -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` |