fs: add support for flag --no-console on windows to hide the console window

This commit is contained in:
albertony 2021-01-24 12:28:39 +01:00 committed by Nick Craig-Wood
parent b569dc11a0
commit 7a496752f3
5 changed files with 33 additions and 0 deletions

View File

@ -382,6 +382,11 @@ func initConfig() {
// Finish parsing any command line flags
configflags.SetFlags(ci)
// Hide console window
if ci.NoConsole {
terminal.HideConsole()
}
// Load filters
err := filterflags.Reload(ctx)
if err != nil {

View File

@ -121,6 +121,7 @@ type ConfigInfo struct {
DownloadHeaders []*HTTPOption
Headers []*HTTPOption
RefreshTimes bool
NoConsole bool
}
// NewConfig creates a new config with everything set to the default

View File

@ -124,6 +124,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {
flags.StringArrayVarP(flagSet, &downloadHeaders, "header-download", "", nil, "Set HTTP header for download transactions")
flags.StringArrayVarP(flagSet, &headers, "header", "", nil, "Set HTTP header for all transactions")
flags.BoolVarP(flagSet, &ci.RefreshTimes, "refresh-times", "", ci.RefreshTimes, "Refresh the modtime of remote files.")
flags.BoolVarP(flagSet, &ci.NoConsole, "no-console", "", ci.NoConsole, "Hide console window. Supported on Windows only.")
}
// ParseHeaders converts the strings passed in via the header flags into HTTPOptions

View File

@ -0,0 +1,7 @@
// +build !windows
package terminal
// HideConsole is only supported on windows
func HideConsole() {
}

View File

@ -0,0 +1,19 @@
// +build windows
package terminal
import (
"syscall"
)
// HideConsole hides the console window and activates another window
func HideConsole() {
getConsoleWindow := syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
showWindow := syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
hwnd, _, _ := getConsoleWindow.Call()
if hwnd != 0 {
showWindow.Call(hwnd, 0)
}
}
}