diff options
author | Colin Cross <ccross@android.com> | 2019-06-20 15:22:50 -0700 |
---|---|---|
committer | Luca Stefani <luca.stefani.ge1@gmail.com> | 2019-09-04 15:14:54 +0200 |
commit | da52017eb2c495e8e6034a0d0339cd7371018e00 (patch) | |
tree | bd1d1b31af9fbafa76827a9953aebd6d5be9786a | |
parent | 7cd9f75a4458f4826c1edf916bdd0c3127b4a91b (diff) | |
download | build_soong-da52017eb2c495e8e6034a0d0339cd7371018e00.tar.gz build_soong-da52017eb2c495e8e6034a0d0339cd7371018e00.tar.bz2 build_soong-da52017eb2c495e8e6034a0d0339cd7371018e00.zip |
Color long running durations when using action table output
When printing the action table, color the duration of commands that
have been running for 30 seconds yellow, and commands that have been
running for 60 seconds red.
Test: manual
Change-Id: I61cb21b0dae10811d345cb9f62cd07915cfc69ee
-rw-r--r-- | ui/terminal/smart_status.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/ui/terminal/smart_status.go b/ui/terminal/smart_status.go index 9638cdf7..8659d4dd 100644 --- a/ui/terminal/smart_status.go +++ b/ui/terminal/smart_status.go @@ -225,9 +225,7 @@ func (s *smartStatusOutput) statusLine(str string) { // Limit line width to the terminal width, otherwise we'll wrap onto // another line and we won't delete the previous line. - if s.termWidth > 0 { - str = s.elide(str) - } + str = elide(str, s.termWidth) // Move to the beginning on the line, turn on bold, print the output, // turn off bold, then clear the rest of the line. @@ -237,11 +235,11 @@ func (s *smartStatusOutput) statusLine(str string) { s.haveBlankLine = false } -func (s *smartStatusOutput) elide(str string) string { - if len(str) > s.termWidth { +func elide(str string, width int) string { + if width > 0 && len(str) > width { // TODO: Just do a max. Ninja elides the middle, but that's // more complicated and these lines aren't that important. - str = str[:s.termWidth] + str = str[:width] } return str @@ -344,9 +342,18 @@ func (s *smartStatusOutput) actionTable() { desc = runningAction.action.Command } - str := fmt.Sprintf(" %2d:%02d %s", seconds/60, seconds%60, desc) - str = s.elide(str) - fmt.Fprint(s.writer, str, ansi.clearToEndOfLine()) + color := "" + if seconds >= 60 { + color = ansi.red() + ansi.bold() + } else if seconds >= 30 { + color = ansi.yellow() + ansi.bold() + } + + durationStr := fmt.Sprintf(" %2d:%02d ", seconds/60, seconds%60) + desc = elide(desc, s.termWidth-len(durationStr)) + durationStr = color + durationStr + ansi.regular() + + fmt.Fprint(s.writer, durationStr, desc, ansi.clearToEndOfLine()) if tableLine < s.tableHeight-1 { fmt.Fprint(s.writer, "\n") } @@ -387,6 +394,14 @@ func (ansiImpl) resetScrollingMargins() string { return fmt.Sprintf("\x1b[r") } +func (ansiImpl) red() string { + return "\x1b[31m" +} + +func (ansiImpl) yellow() string { + return "\x1b[33m" +} + func (ansiImpl) bold() string { return "\x1b[1m" } |