Skip to content

Commit

Permalink
Merge pull request #260 from antifuchs/be-friendly-to-non-ttys
Browse files Browse the repository at this point in the history
Detect non-tty master operation & act accordingly
  • Loading branch information
turadg committed Mar 3, 2013
2 parents 1f7bb9b + 5ee4387 commit 014c262
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions go/statuschart/statuschart.go
Expand Up @@ -30,7 +30,8 @@ type StatusChart struct {

directLogger *slog.ShinyLogger

extraOutput string
extraOutput string
terminalSupported bool
}

var theChart *StatusChart
Expand All @@ -44,13 +45,14 @@ func Start(tree *processtree.ProcessTree, done chan bool) chan bool {
theChart.Commands = tree.Commands
theChart.update = make(chan bool, 10)
theChart.directLogger = slog.NewShinyLogger(os.Stdout, os.Stderr)
theChart.terminalSupported = true

scw := &StringChannelWriter{make(chan string, 10)}
slog.DefaultLogger = slog.NewShinyLogger(scw, scw)

termios, err := ttyutils.NoEcho(uintptr(os.Stdout.Fd()))
if err != nil {
slog.Error(err)
theChart.terminalSupported = false
}

ticker := time.Tick(1000 * time.Millisecond)
Expand All @@ -61,7 +63,9 @@ func Start(tree *processtree.ProcessTree, done chan bool) chan bool {
done <- true
return
case <-ticker:
theChart.draw()
if theChart.terminalSupported {
theChart.draw()
}
case output := <-scw.Notif:
theChart.L.Lock()
if theChart.drawnInitial {
Expand Down Expand Up @@ -107,7 +111,11 @@ func (s *StatusChart) draw() {
if s.drawnInitial {
lengthOfOutput := s.lengthOfOutput()
numberOfOutputLines := s.numberOfSlaves + len(s.Commands) + lengthOfOutput + 3
fmt.Printf("\033[%dA", numberOfOutputLines)
if s.terminalSupported {
fmt.Printf("\033[%dA", numberOfOutputLines)
} else {
fmt.Printf("\n==== UPDATED %s =====\n", time.Now().Format(time.UnixDate))
}
} else {
s.drawnInitial = true
}
Expand Down

0 comments on commit 014c262

Please sign in to comment.