Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix console color output on Windows #5612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix missing ACK in redis output. {issue}5404[5404]
- Change add_kubernetes_metadata to attempt detection of namespace. {pull}5482[5482]
- Avoid double slash when join url and path {pull}5517[5517]
- Fix console color output for Windows. {issue}5611[5611]

*Auditbeat*

Expand Down
7 changes: 7 additions & 0 deletions libbeat/testing/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"io"
"os"
"runtime"
"strings"

"github.com/fatih/color"
"github.com/mattn/go-colorable"
)

// ConsoleDriver outputs test result to the given stdout/stderr descriptors
Expand All @@ -26,6 +28,11 @@ func NewConsoleDriver(stdout io.Writer) *ConsoleDriver {
// NewConsoleDriverWithKiller initializes and returns a new console driver with output file
// Killer function will be called on fatal errors
func NewConsoleDriverWithKiller(stdout io.Writer, killer func()) *ConsoleDriver {
// On Windows we must wrap file outputs with a Colorable to achieve the right
// escape sequences.
if f, ok := stdout.(*os.File); ok && runtime.GOOS == "windows" {
stdout = colorable.NewColorable(f)
}
return &ConsoleDriver{
Stdout: stdout,
level: 0,
Expand Down