blob: 92f29940508253a28805643a460c1f173e1b2467 [file] [log] [blame]
Dan Willemsenb82471a2018-05-17 16:37:09 -07001// 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 (
Colin Cross097ed2a2019-06-08 21:48:58 -070018 "io"
19
Dan Willemsenb82471a2018-05-17 16:37:09 -070020 "android/soong/ui/status"
21)
22
Dan Willemsenb82471a2018-05-17 16:37:09 -070023// 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.
Colin Cross3c0fe0e2021-02-10 13:11:18 -080029func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput {
cherokeeMetaf7119b52024-07-11 16:52:18 -070030 canUseSmartFormatting := !forceSimpleOutput && isSmartTerminal(w)
31 formatter := newFormatter(canUseSmartFormatting, statusFormat, quietBuild)
Dan Willemsenb82471a2018-05-17 16:37:09 -070032
cherokeeMetaf7119b52024-07-11 16:52:18 -070033 if canUseSmartFormatting {
Sasha Smundak827aead2021-11-19 11:22:54 -080034 return NewSmartStatusOutput(w, formatter)
Sasha Smundak2cec8df2022-05-06 16:04:44 -070035 } else {
36 return NewSimpleStatusOutput(w, formatter, forceKeepANSI)
Dan Willemsenb82471a2018-05-17 16:37:09 -070037 }
38}