Beispiel #1
0
// Print the codeword contents and type to terminal. For debugging.
func (c *Codeword) Print() {

	payload := ""
	var color *color.Color = blue

	switch c.Type {

	case CodewordTypeAddress:
		payload = c.Adress()
		color = red

	case CodewordTypeMessage:
		payload = ""
		color = green

	default:
		color = blue

	}

	parity := utils.TernaryStr(c.ValidParity, "", "*")
	color.Printf("%s %s %s ", c.Type, payload, parity)
	corr := c.BitCorrections
	if corr > 0 {
		color.Printf("%d bits corrected", corr)
	}

	println("")
}
Beispiel #2
0
// consolePrintf - same as print with a new line.
func consolePrintf(tag string, c *color.Color, format string, a ...interface{}) {
	privateMutex.Lock()
	defer privateMutex.Unlock()

	switch tag {
	case "Debug":
		// if no arguments are given do not invoke debug printer.
		if len(a) == 0 {
			return
		}
		output := color.Output
		color.Output = stderrColoredOutput
		if isatty.IsTerminal(os.Stderr.Fd()) {
			c.Print(ProgramName() + ": <DEBUG> ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": <DEBUG> ")
			fmt.Fprintf(color.Output, format, a...)
		}
		color.Output = output
	case "Fatal":
		fallthrough
	case "Error":
		// if no arguments are given do not invoke fatal and error printer.
		if len(a) == 0 {
			return
		}
		output := color.Output
		color.Output = stderrColoredOutput
		if isatty.IsTerminal(os.Stderr.Fd()) {
			c.Print(ProgramName() + ": <ERROR> ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": <ERROR> ")
			fmt.Fprintf(color.Output, format, a...)
		}
		color.Output = output
	case "Info":
		// if no arguments are given do not invoke info printer.
		if len(a) == 0 {
			return
		}
		if isatty.IsTerminal(os.Stdout.Fd()) {
			c.Print(ProgramName() + ": ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": ")
			fmt.Fprintf(color.Output, format, a...)
		}
	default:
		if isatty.IsTerminal(os.Stdout.Fd()) {
			c.Printf(format, a...)
		} else {
			fmt.Fprintf(color.Output, format, a...)
		}
	}
}
Beispiel #3
0
func printDatagram(out *color.Color, d *protocol.Datagram) {
	re := regexp.MustCompilePOSIX("^00000")

	out.Printf("FROM: %s\n", d.From)
	out.Printf("SIZE: %d\n", len(d.Data))
	data := strings.TrimLeft(hex.Dump(d.Data), "0")
	out.Printf("DATA: 000" + re.ReplaceAllString(data, "      "))
	color.Set(color.Bold)
}
Beispiel #4
0
func (s *RangeHistogram) ResumeHistogram(out *color.Color) {
	out.Printf("\n %s:", s.name_)

	sortedHisto := make([]int, len(s.data_))

	minKey := 999999999
	maxKey := 0
	for key, _ := range s.data_ {
		if key < minKey {
			minKey = key
		}
		if key > maxKey {
			maxKey = key
		}
	}

	for key, val := range s.data_ {
		sortedHisto[key-minKey] = val
	}

	for k, v := range sortedHisto {
		out.Printf("\n [%d]: %d", k, v)
	}
}
Beispiel #5
0
// consolePrintf - same as print with a new line.
func consolePrintf(tag string, c *color.Color, format string, a ...interface{}) {
	privateMutex.Lock()
	defer privateMutex.Unlock()

	switch tag {
	case "Debug":
		output := color.Output
		color.Output = stderrColoredOutput
		if isatty.IsTerminal(os.Stderr.Fd()) {
			c.Print(ProgramName() + ": <DEBUG> ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": <DEBUG> ")
			fmt.Fprintf(color.Output, format, a...)
		}
		color.Output = output
	case "Fatal":
		fallthrough
	case "Error":
		output := color.Output
		color.Output = stderrColoredOutput
		if isatty.IsTerminal(os.Stderr.Fd()) {
			c.Print(ProgramName() + ": <ERROR> ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": <ERROR> ")
			fmt.Fprintf(color.Output, format, a...)
		}
		color.Output = output
	case "Info":
		if isatty.IsTerminal(os.Stdout.Fd()) {
			c.Print(ProgramName() + ": ")
			c.Printf(format, a...)
		} else {
			fmt.Fprint(color.Output, ProgramName()+": ")
			fmt.Fprintf(color.Output, format, a...)
		}
	default:
		if isatty.IsTerminal(os.Stdout.Fd()) {
			c.Printf(format, a...)
		} else {
			fmt.Fprintf(color.Output, format, a...)
		}
	}
}
Beispiel #6
0
func (s *RangeStatistic) ResumeRangeAv(out *color.Color) {
	out.Printf("\n %s: min=%d, max=%d av=%f", s.name_, s.min_, s.max_, float64(s.total_)/float64(s.count_))
}
Beispiel #7
0
func (s *RangeStatistic) ResumeRange(out *color.Color) {
	out.Printf("\n %s: min=%d, max=%d", s.name_, s.min_, s.max_)
}
Beispiel #8
0
func (s *ScalarStatistic) ResumeAv(out *color.Color) {
	out.Printf("\n %s av: %f", s.name_, float64(s.total_)/float64(s.count_))
}
Beispiel #9
0
func (s *ScalarStatistic) Resume(out *color.Color) {
	out.Printf("\n %s: %d", s.name_, s.total_)
}
Beispiel #10
0
func (s *RangeHistogram) ResumeHistogramUnsort(out *color.Color) {
	out.Printf("\n %s: %d", s.name_, s.total_)
	for k, v := range s.data_ {
		out.Printf("\n [%d]: %d", k, v)
	}
}