Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
clean up task watching when disabled
Browse files Browse the repository at this point in the history
when a task is disabled, the same computation done on a SIGINT (how many lines to jump
before printing and exiting) was not being done.  This fixes that, and
simplifies how that line count is communicated among the goroutines.

fixes #365
  • Loading branch information
pittma committed Oct 21, 2015
1 parent 6538e59 commit 34bc848
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions cmd/pulsectl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,14 @@ func watchTask(ctx *cli.Context) {

// catch interrupt so we signal the server we are done before exiting
c := make(chan os.Signal, 1)
lineCountChan := make(chan int)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
var lines int
go func() {
var lines int
for {
select {
case lines = <-lineCountChan:
case <-c:
fmt.Printf("%sStopping task watch\n", strings.Repeat("\n", lines))
r.Close()
return
}
}
<-c
fmt.Printf("%sStopping task watch\n", strings.Repeat("\n", lines))
r.Close()
return
}()

w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
Expand All @@ -346,11 +340,11 @@ func watchTask(ctx *cli.Context) {
event.Source,
)
}
lineCountChan <- len(e.Event)
fmt.Fprintf(w, "\033[%dA\n", len(e.Event)+1)
lines = len(e.Event)
fmt.Fprintf(w, "\033[%dA\n", lines+1)
w.Flush()
default:
fmt.Printf("[%s]\n", e.EventType)
fmt.Printf("%s[%s]\n", strings.Repeat("\n", lines), e.EventType)
}

case <-r.DoneChan:
Expand Down

0 comments on commit 34bc848

Please sign in to comment.