Commit 7658ff69 authored by Alessio Caiazza's avatar Alessio Caiazza 🔴

Merge branch 'windows/colored-logging' into 'master'

Fix color output on Windows

See merge request gitlab-org/gitlab-runner!1208
parents dc226fa2 8b144832
......@@ -1076,6 +1076,7 @@
"gitlab.com/gitlab-org/gitlab-terminal",
"golang.org/x/crypto/ssh",
"golang.org/x/net/context",
"golang.org/x/sys/windows",
"gopkg.in/yaml.v2",
"k8s.io/api/core/v1",
"k8s.io/apimachinery/pkg/api/resource",
......
......@@ -158,6 +158,10 @@ ignored = ["test", "appengine"]
name = "github.com/markelog/trie"
branch = "master"
[[constraint]]
name = "golang.org/x/sys"
branch = "master"
##
## Refrain innovations ;)
##
......
// +build !windows
package cli_helpers
func InitCli() {}
package cli_helpers
import (
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
)
// InitCli initializes the Windows console window by activating virtual terminal features.
// Calling this function enables colored terminal output.
func InitCli() {
setConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) // enable VT processing on standard output stream
setConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) // enable VT processing on standard error stream
}
// setConsoleMode sets the given flags on the given
// console standard stream.
func setConsoleMode(handle windows.Handle, flags uint32) {
var mode uint32
// add console mode flag
if err := windows.GetConsoleMode(handle, &mode); err == nil {
err := windows.SetConsoleMode(handle, mode|flags)
if err != nil {
logrus.WithError(err).Info("Failed to set console mode for cli")
}
}
}
......@@ -52,6 +52,7 @@ func main() {
logrus.Fatalln("Command", command, "not found.")
}
cli_helpers.InitCli()
cli_helpers.LogRuntimePlatform(app)
cli_helpers.SetupCPUProfile(app)
cli_helpers.FixHOME(app)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment