Merge "Color long running durations when using action table output"

This commit is contained in:
Colin Cross 2019-06-24 21:38:51 +00:00 committed by Gerrit Code Review
commit bbeb2c1a50
1 changed files with 24 additions and 9 deletions

View File

@ -225,9 +225,7 @@ func (s *smartStatusOutput) statusLine(str string) {
// Limit line width to the terminal width, otherwise we'll wrap onto // Limit line width to the terminal width, otherwise we'll wrap onto
// another line and we won't delete the previous line. // another line and we won't delete the previous line.
if s.termWidth > 0 { str = elide(str, s.termWidth)
str = s.elide(str)
}
// Move to the beginning on the line, turn on bold, print the output, // Move to the beginning on the line, turn on bold, print the output,
// turn off bold, then clear the rest of the line. // turn off bold, then clear the rest of the line.
@ -237,11 +235,11 @@ func (s *smartStatusOutput) statusLine(str string) {
s.haveBlankLine = false s.haveBlankLine = false
} }
func (s *smartStatusOutput) elide(str string) string { func elide(str string, width int) string {
if len(str) > s.termWidth { if width > 0 && len(str) > width {
// TODO: Just do a max. Ninja elides the middle, but that's // TODO: Just do a max. Ninja elides the middle, but that's
// more complicated and these lines aren't that important. // more complicated and these lines aren't that important.
str = str[:s.termWidth] str = str[:width]
} }
return str return str
@ -344,9 +342,18 @@ func (s *smartStatusOutput) actionTable() {
desc = runningAction.action.Command desc = runningAction.action.Command
} }
str := fmt.Sprintf(" %2d:%02d %s", seconds/60, seconds%60, desc) color := ""
str = s.elide(str) if seconds >= 60 {
fmt.Fprint(s.writer, str, ansi.clearToEndOfLine()) 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 { if tableLine < s.tableHeight-1 {
fmt.Fprint(s.writer, "\n") fmt.Fprint(s.writer, "\n")
} }
@ -387,6 +394,14 @@ func (ansiImpl) resetScrollingMargins() string {
return fmt.Sprintf("\x1b[r") return fmt.Sprintf("\x1b[r")
} }
func (ansiImpl) red() string {
return "\x1b[31m"
}
func (ansiImpl) yellow() string {
return "\x1b[33m"
}
func (ansiImpl) bold() string { func (ansiImpl) bold() string {
return "\x1b[1m" return "\x1b[1m"
} }