Colin Cross | ce52535 | 2019-06-08 18:58:00 -0700 | [diff] [blame^] | 1 | // Copyright 2019 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 ( |
| 18 | "fmt" |
| 19 | |
| 20 | "android/soong/ui/status" |
| 21 | ) |
| 22 | |
| 23 | type dumbStatusOutput struct { |
| 24 | writer Writer |
| 25 | formatter formatter |
| 26 | } |
| 27 | |
| 28 | // NewDumbStatusOutput returns a StatusOutput that represents the |
| 29 | // current build status similarly to Ninja's built-in terminal |
| 30 | // output. |
| 31 | func NewDumbStatusOutput(w Writer, formatter formatter) status.StatusOutput { |
| 32 | return &dumbStatusOutput{ |
| 33 | writer: w, |
| 34 | formatter: formatter, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func (s *dumbStatusOutput) Message(level status.MsgLevel, message string) { |
| 39 | if level >= status.StatusLvl { |
| 40 | fmt.Fprintln(s.writer, s.formatter.message(level, message)) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func (s *dumbStatusOutput) StartAction(action *status.Action, counts status.Counts) { |
| 45 | } |
| 46 | |
| 47 | func (s *dumbStatusOutput) FinishAction(result status.ActionResult, counts status.Counts) { |
| 48 | str := result.Description |
| 49 | if str == "" { |
| 50 | str = result.Command |
| 51 | } |
| 52 | |
| 53 | progress := s.formatter.progress(counts) + str |
| 54 | |
| 55 | output := s.formatter.result(result) |
| 56 | output = string(stripAnsiEscapes([]byte(output))) |
| 57 | |
| 58 | if output != "" { |
| 59 | fmt.Fprint(s.writer, progress, "\n", output) |
| 60 | } else { |
| 61 | fmt.Fprintln(s.writer, progress) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func (s *dumbStatusOutput) Flush() {} |