Merge "Revert "Use SIGWINCH to update terminal size""
This commit is contained in:
commit
e77a57336f
|
@ -17,11 +17,8 @@ package terminal
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"android/soong/ui/status"
|
||||
)
|
||||
|
@ -33,29 +30,18 @@ type smartStatusOutput struct {
|
|||
lock sync.Mutex
|
||||
|
||||
haveBlankLine bool
|
||||
|
||||
termWidth int
|
||||
sigwinch chan os.Signal
|
||||
}
|
||||
|
||||
// NewSmartStatusOutput returns a StatusOutput that represents the
|
||||
// current build status similarly to Ninja's built-in terminal
|
||||
// output.
|
||||
func NewSmartStatusOutput(w io.Writer, formatter formatter) status.StatusOutput {
|
||||
s := &smartStatusOutput{
|
||||
return &smartStatusOutput{
|
||||
writer: w,
|
||||
formatter: formatter,
|
||||
|
||||
haveBlankLine: true,
|
||||
|
||||
sigwinch: make(chan os.Signal),
|
||||
}
|
||||
|
||||
s.updateTermSize()
|
||||
|
||||
s.startSigwinch()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) Message(level status.MsgLevel, message string) {
|
||||
|
@ -115,8 +101,6 @@ func (s *smartStatusOutput) Flush() {
|
|||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
s.stopSigwinch()
|
||||
|
||||
s.requestLine()
|
||||
}
|
||||
|
||||
|
@ -153,8 +137,16 @@ 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)
|
||||
//
|
||||
// Run this on every line in case the window has been resized while
|
||||
// we're printing. This could be optimized to only re-run when we get
|
||||
// SIGWINCH if it ever becomes too time consuming.
|
||||
if max, ok := termWidth(s.writer); ok {
|
||||
if len(str) > max {
|
||||
// TODO: Just do a max. Ninja elides the middle, but that's
|
||||
// more complicated and these lines aren't that important.
|
||||
str = str[:max]
|
||||
}
|
||||
}
|
||||
|
||||
// Move to the beginning on the line, turn on bold, print the output,
|
||||
|
@ -164,35 +156,3 @@ func (s *smartStatusOutput) statusLine(str string) {
|
|||
fmt.Fprint(s.writer, start, str, end)
|
||||
s.haveBlankLine = false
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) elide(str string) string {
|
||||
if len(str) > s.termWidth {
|
||||
// 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]
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) startSigwinch() {
|
||||
signal.Notify(s.sigwinch, syscall.SIGWINCH)
|
||||
go func() {
|
||||
for _ = range s.sigwinch {
|
||||
s.lock.Lock()
|
||||
s.updateTermSize()
|
||||
s.lock.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) stopSigwinch() {
|
||||
signal.Stop(s.sigwinch)
|
||||
close(s.sigwinch)
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) updateTermSize() {
|
||||
if w, ok := termWidth(s.writer); ok {
|
||||
s.termWidth = w
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package terminal
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"android/soong/ui/status"
|
||||
|
@ -261,8 +260,6 @@ func TestSmartStatusOutputWidthChange(t *testing.T) {
|
|||
|
||||
runner.startAction(action)
|
||||
smart.termWidth = 30
|
||||
// Fake a SIGWINCH
|
||||
stat.(*smartStatusOutput).sigwinch <- syscall.SIGWINCH
|
||||
runner.finishAction(result)
|
||||
|
||||
stat.Flush()
|
||||
|
|
Loading…
Reference in New Issue