Implement missing bits in result listing

This commit is contained in:
Arturo Filastò
2018-06-22 11:53:10 +02:00
parent 15c901ed68
commit 703b260903
5 changed files with 97 additions and 21 deletions
+15
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"strings"
"sync"
"time"
@@ -60,6 +61,16 @@ func New(w io.Writer) *Handler {
}
}
func logSectionTitle(w io.Writer, f log.Fields) error {
colWidth := 24
title := f.Get("title").(string)
fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n")
fmt.Fprintf(w, "┃ %s ┃\n", RightPad(title, colWidth))
fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n")
return nil
}
// TypedLog is used for handling special "typed" logs to the CLI
func (h *Handler) TypedLog(t string, e *log.Entry) error {
switch t {
@@ -70,6 +81,10 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error {
return nil
case "result_item":
return logResultItem(h.Writer, e.Fields)
case "result_summary":
return logResultSummary(h.Writer, e.Fields)
case "section_title":
return logSectionTitle(h.Writer, e.Fields)
default:
return h.DefaultLog(e)
}
+17 -4
View File
@@ -10,10 +10,6 @@ import (
"github.com/apex/log"
)
func RightPad(str string, length int) string {
return str + strings.Repeat(" ", length-len(str))
}
// XXX Copy-pasta from nettest/groups
// PerformanceSummary is the result summary for a performance test
type PerformanceSummary struct {
@@ -145,3 +141,20 @@ func logResultItem(w io.Writer, f log.Fields) error {
}
return nil
}
func logResultSummary(w io.Writer, f log.Fields) error {
networks := f.Get("total_networks").(int64)
tests := f.Get("total_tests").(int64)
dataUp := f.Get("total_data_usage_up").(int64)
dataDown := f.Get("total_data_usage_down").(int64)
// └┬──────────────┬──────────────┬──────────────┬
fmt.Fprintf(w, " │ %s │ %s │ %s │\n",
RightPad(fmt.Sprintf("%d tests", tests), 12),
RightPad(fmt.Sprintf("%d nets", networks), 12),
RightPad(fmt.Sprintf("%d ⬆ %d ⬇", dataUp, dataDown), 12))
fmt.Fprintf(w, " └──────────────┴──────────────┴──────────────┘\n")
return nil
}
+10
View File
@@ -0,0 +1,10 @@
package cli
import (
"strings"
"unicode/utf8"
)
func RightPad(str string, length int) string {
return str + strings.Repeat(" ", length-utf8.RuneCountInString(str))
}