Add environment variable to force keeping ANSI codes

If SOONG_UI_ANSI_OUTPUT is set to a true value force the simple status
output to keep ANSI codes.  This will allow buildbots to collect logs
with ANSI codes in them.  Smart status output is not affected as it
always keeps ANSI codes.

Bug: 147310922
Test: manual
Change-Id: I0b78ceebb65125b8e8dafb4787816fb679d3eb3e
This commit is contained in:
Colin Cross
2021-02-10 13:11:18 -08:00
parent 72a28a6a13
commit 3c0fe0edc0
6 changed files with 22 additions and 11 deletions

View File

@@ -24,15 +24,17 @@ import (
type simpleStatusOutput struct {
writer io.Writer
formatter formatter
keepANSI bool
}
// NewSimpleStatusOutput returns a StatusOutput that represents the
// current build status similarly to Ninja's built-in terminal
// output.
func NewSimpleStatusOutput(w io.Writer, formatter formatter) status.StatusOutput {
func NewSimpleStatusOutput(w io.Writer, formatter formatter, keepANSI bool) status.StatusOutput {
return &simpleStatusOutput{
writer: w,
formatter: formatter,
keepANSI: keepANSI,
}
}
@@ -54,7 +56,9 @@ func (s *simpleStatusOutput) FinishAction(result status.ActionResult, counts sta
progress := s.formatter.progress(counts) + str
output := s.formatter.result(result)
output = string(stripAnsiEscapes([]byte(output)))
if !s.keepANSI {
output = string(stripAnsiEscapes([]byte(output)))
}
if output != "" {
fmt.Fprint(s.writer, progress, "\n", output)