Exemple #1
0
func ttyStart(tree *processtree.ProcessTree, done, quit chan bool) {
	go func() {
		scw := &StringChannelWriter{make(chan string, 10)}
		slog.SetDefaultLogger(slog.NewShinyLogger(scw, scw))

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

		for {
			select {
			case <-quit:
				ttyutils.RestoreTerminalState(uintptr(os.Stdout.Fd()), termios)
				done <- true
				return
			case output := <-scw.Notif:
				theChart.L.Lock()
				if theChart.drawnInitial {
					print(output)
				}
				theChart.extraOutput += output
				theChart.L.Unlock()
				theChart.draw()
			case <-theChart.update:
				theChart.draw()
			}
		}
	}()
}
Exemple #2
0
func Start(tree *processtree.ProcessTree, done chan bool) chan bool {
	quit := make(chan bool)
	go func() {
		theChart = &StatusChart{}
		theChart.RootSlave = tree.Root
		theChart.numberOfSlaves = len(tree.SlavesByName)
		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 {
			theChart.terminalSupported = false
		}

		ticker := time.Tick(1000 * time.Millisecond)
		for {
			select {
			case <-quit:
				ttyutils.RestoreTerminalState(uintptr(os.Stdout.Fd()), termios)
				done <- true
				return
			case <-ticker:
				if theChart.terminalSupported {
					theChart.draw()
				}
			case output := <-scw.Notif:
				theChart.L.Lock()
				if theChart.drawnInitial {
					print(output)
				}
				theChart.extraOutput += output
				theChart.L.Unlock()
				theChart.draw()
			case <-tree.StateChanged:
				theChart.draw()
			case <-theChart.update:
				theChart.draw()
			}
		}
	}()
	return quit
}