Exemplo n.º 1
0
func getStatusLine(status string, opts *ScriptRunnerOptions) string {
	w := term.GetTerminalWidth()

	statusString := "[" + status + term.Reset + "] "

	var nodeAverageRunDuration string
	if opts.Node.TrackingData == nil {
		nodeAverageRunDuration = "??"
	} else {
		nodeAverageRunDuration = FormatDuration(opts.Node.TrackingData.GetAverageRunDuration())
	}

	var graphAverageRunTime string
	if opts.Graph.AverageRunTime.Nanoseconds() > 0 {
		graphAverageRunTime = FormatDuration(opts.Graph.AverageRunTime)
	} else {
		graphAverageRunTime = "??"
	}

	nodeTimeString := fmt.Sprintf("%s (%s)", FormatDuration(time.Since(opts.StartTime)), nodeAverageRunDuration)
	graphTimeString := fmt.Sprintf("%s (%s)", FormatDuration(time.Since(opts.Graph.StartTime)), graphAverageRunTime)

	timeString := fmt.Sprintf(" %16s / %16s", nodeTimeString, graphTimeString)

	scriptCountStr := fmt.Sprintf("(%v/%v)", opts.ScriptIdx+1, opts.ScriptCount)
	scriptFmtString := fmt.Sprintf("%%s %%7s %%-%vs %%s", w-7-len(statusString)-len(timeString))
	scriptStr := opts.RelPath
	if len(opts.SkipReason) > 0 {
		scriptStr += " (skipped because: " + opts.SkipReason + ")"
	}
	return fmt.Sprintf(scriptFmtString, statusString, scriptCountStr, scriptStr, timeString)
}
Exemplo n.º 2
0
func (w ProcessWriter) Write(p []byte) (n int, err error) {
	for i := 0; i < len(p); i++ {
		w.buf.WriteByte(p[i])
		if p[i] == '\n' {
			blankLine := ""
			termWidth := term.GetTerminalWidth()
			for i := 0; i < termWidth; i++ {
				blankLine += " "
			}

			fmt.Print("\r", blankLine, "\r", w.buf.String())
			w.Opts.GraphRunOpts.TryLog(w.buf.String())

			fmt.Printf(getStatusLine(term.FgCyan+"RUNNING ", w.Opts))
			w.buf.Reset()
		}
	}
	return len(p), nil
}