Commit 8b144832 authored by Axel D.'s avatar Axel D. Committed by Alessio Caiazza

Colored output failed on Windows machines - fixed now.

GitLab Runner terminal output failed to output color codes on Windows machines. Instead, code gibberish was output.

This merge request fixes color output on Windows machines.
parent dc226fa2
......@@ -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