Use SIGWINCH to update terminal size

Instead of reading the terminal size on every status update, register
for SIGWINCH to read and store the size when it changes.

This reapplies I555ad21a31a2c924ab0ca681e0c8f00df42a370a with a fix
for a race condition in TestSmartStatusOutputWidthChange.

Test: status_test.go
Change-Id: If342cb4cc8e4ed57af9e3bb417758348c9c41247
This commit is contained in:
Colin Cross
2019-06-11 23:01:36 -07:00
parent e77a57336f
commit 4355ee64a9
2 changed files with 61 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ package terminal
import (
"bytes"
"fmt"
"syscall"
"testing"
"android/soong/ui/status"
@@ -252,6 +253,8 @@ func actionWithOuptutWithAnsiCodes(stat status.StatusOutput) {
func TestSmartStatusOutputWidthChange(t *testing.T) {
smart := &fakeSmartTerminal{termWidth: 40}
stat := NewStatusOutput(smart, "", false)
smartStat := stat.(*smartStatusOutput)
smartStat.sigwinchHandled = make(chan bool)
runner := newRunner(stat, 2)
@@ -260,6 +263,9 @@ func TestSmartStatusOutputWidthChange(t *testing.T) {
runner.startAction(action)
smart.termWidth = 30
// Fake a SIGWINCH
smartStat.sigwinch <- syscall.SIGWINCH
<-smartStat.sigwinchHandled
runner.finishAction(result)
stat.Flush()