xref: /aosp_15_r20/build/soong/ui/terminal/status.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package terminal
16
17import (
18	"io"
19
20	"android/soong/ui/status"
21)
22
23// NewStatusOutput returns a StatusOutput that represents the
24// current build status similarly to Ninja's built-in terminal
25// output.
26//
27// statusFormat takes nearly all the same options as NINJA_STATUS.
28// %c is currently unsupported.
29func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput {
30	canUseSmartFormatting := !forceSimpleOutput && isSmartTerminal(w)
31	formatter := newFormatter(canUseSmartFormatting, statusFormat, quietBuild)
32
33	if canUseSmartFormatting {
34		return NewSmartStatusOutput(w, formatter)
35	} else {
36		return NewSimpleStatusOutput(w, formatter, forceKeepANSI)
37	}
38}
39