diff options
author | 2019-09-20 15:01:51 -0700 | |
---|---|---|
committer | 2019-09-20 15:03:31 -0700 | |
commit | f0b987ecba2b014a8bf11b93367b8d5368bdf629 (patch) | |
tree | 4219a2e52351ed6893fc924ad807b244b6377b55 /ui/terminal | |
parent | bf8f57e2f6956a88437009754ec8c935a3f06720 (diff) |
status table: don't write newlines in non-scrolling terminals
Multiple terminals have had issues with writing newlines into the
non-scrolling region, just set the cursor to the beginning of the
next line instead.
Test: m nothing in JediTerm
Change-Id: I2e434f4cc263ca13b82889a79d6a8bb48d084cb3
Diffstat (limited to 'ui/terminal')
-rw-r--r-- | ui/terminal/smart_status.go | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/ui/terminal/smart_status.go b/ui/terminal/smart_status.go index aa7e50a4d..efcfd4359 100644 --- a/ui/terminal/smart_status.go +++ b/ui/terminal/smart_status.go @@ -334,48 +334,40 @@ func (s *smartStatusOutput) actionTable() { scrollingHeight := s.termHeight - s.tableHeight // Update the scrolling region in case the height of the terminal changed + fmt.Fprint(s.writer, ansi.setScrollingMargins(1, scrollingHeight)) - // Move the cursor to the first line of the non-scrolling region - fmt.Fprint(s.writer, ansi.setCursor(scrollingHeight+1, 1)) // Write as many status lines as fit in the table - var tableLine int - var runningAction actionTableEntry - for tableLine, runningAction = range s.runningActions { + for tableLine := 0; tableLine < s.tableHeight; tableLine++ { if tableLine >= s.tableHeight { break } + // Move the cursor to the correct line of the non-scrolling region + fmt.Fprint(s.writer, ansi.setCursor(scrollingHeight+1+tableLine, 1)) - seconds := int(time.Since(runningAction.startTime).Round(time.Second).Seconds()) + if tableLine < len(s.runningActions) { + runningAction := s.runningActions[tableLine] - desc := runningAction.action.Description - if desc == "" { - desc = runningAction.action.Command - } + seconds := int(time.Since(runningAction.startTime).Round(time.Second).Seconds()) - color := "" - if seconds >= 60 { - color = ansi.red() + ansi.bold() - } else if seconds >= 30 { - color = ansi.yellow() + ansi.bold() - } + desc := runningAction.action.Description + if desc == "" { + desc = runningAction.action.Command + } - durationStr := fmt.Sprintf(" %2d:%02d ", seconds/60, seconds%60) - desc = elide(desc, s.termWidth-len(durationStr)) - durationStr = color + durationStr + ansi.regular() + color := "" + if seconds >= 60 { + color = ansi.red() + ansi.bold() + } else if seconds >= 30 { + color = ansi.yellow() + ansi.bold() + } - fmt.Fprint(s.writer, durationStr, desc, ansi.clearToEndOfLine()) - if tableLine < s.tableHeight-1 { - fmt.Fprint(s.writer, "\n") + 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) } - } - - // Clear any remaining lines in the table - for ; tableLine < s.tableHeight; tableLine++ { fmt.Fprint(s.writer, ansi.clearToEndOfLine()) - if tableLine < s.tableHeight-1 { - fmt.Fprint(s.writer, "\n") - } } // Move the cursor back to the last line of the scrolling region |