Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 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 | |
| 15 | package terminal |
| 16 | |
| 17 | import ( |
Colin Cross | 097ed2a | 2019-06-08 21:48:58 -0700 | [diff] [blame] | 18 | "io" |
| 19 | |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 20 | "android/soong/ui/status" |
| 21 | ) |
| 22 | |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 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. |
Colin Cross | 3c0fe0e | 2021-02-10 13:11:18 -0800 | [diff] [blame] | 29 | func NewStatusOutput(w io.Writer, statusFormat string, forceSimpleOutput, quietBuild, forceKeepANSI bool) status.StatusOutput { |
cherokeeMeta | f7119b5 | 2024-07-11 16:52:18 -0700 | [diff] [blame] | 30 | canUseSmartFormatting := !forceSimpleOutput && isSmartTerminal(w) |
| 31 | formatter := newFormatter(canUseSmartFormatting, statusFormat, quietBuild) |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 32 | |
cherokeeMeta | f7119b5 | 2024-07-11 16:52:18 -0700 | [diff] [blame] | 33 | if canUseSmartFormatting { |
Sasha Smundak | 827aead | 2021-11-19 11:22:54 -0800 | [diff] [blame] | 34 | return NewSmartStatusOutput(w, formatter) |
Sasha Smundak | 2cec8df | 2022-05-06 16:04:44 -0700 | [diff] [blame] | 35 | } else { |
| 36 | return NewSimpleStatusOutput(w, formatter, forceKeepANSI) |
Dan Willemsen | b82471a | 2018-05-17 16:37:09 -0700 | [diff] [blame] | 37 | } |
| 38 | } |