From 8c540b6bdc745ee0c0eab7cb6075d5289ec45873 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 27 Jun 2026 11:17:03 +0300 Subject: Restyle HTML output to stats.foo.zone style; bump to 0.5.3 --- fixtures/Host.Boots.HTML.expected | 31 ++----- fixtures/Host.Downtime.HTML.expected | 31 ++----- fixtures/Host.Lifespan.HTML.expected | 31 ++----- fixtures/Host.Score.HTML.expected | 31 ++----- fixtures/Host.Uptime.HTML.expected | 31 ++----- fixtures/Kernel.Boots.HTML.expected | 31 ++----- fixtures/Kernel.Score.HTML.expected | 31 ++----- fixtures/Kernel.Uptime.HTML.expected | 31 ++----- fixtures/KernelMajor.Boots.HTML.expected | 31 ++----- fixtures/KernelMajor.Score.HTML.expected | 31 ++----- fixtures/KernelMajor.Uptime.HTML.expected | 31 ++----- fixtures/KernelName.Boots.HTML.expected | 31 ++----- fixtures/KernelName.Score.HTML.expected | 31 ++----- fixtures/KernelName.Uptime.HTML.expected | 31 ++----- internal/daemon/daemon_test.go | 2 +- internal/goprecords/report.go | 132 ++++++++++++++++++++++++------ internal/goprecords/report_format.go | 71 +++++++++------- internal/goprecords/report_test.go | 4 +- internal/version/version.go | 2 +- 19 files changed, 266 insertions(+), 379 deletions(-) diff --git a/fixtures/Host.Boots.HTML.expected b/fixtures/Host.Boots.HTML.expected index eb11339..0aeb36c 100644 --- a/fixtures/Host.Boots.HTML.expected +++ b/fixtures/Host.Boots.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Boots's by Host - - -

Top 3 Boots's by Host


-
-Boots is the total number of host boots over the entire lifespan.
-
-
+-----+----------------+-------+-----------------------------+------------------+
-| Pos |           Host | Boots |                 Last Kernel |          Updated |
-+-----+----------------+-------+-----------------------------+------------------+
-|  1. |  alphacentauri |   671 |     FreeBSD 11.4-RELEASE-p7 | 2026-03-03 18:29 |
-|  2. |           mars |   207 |         Linux 3.2.0-4-amd64 | 2026-03-03 18:29 |
-|  3. |       callisto |   153 | Linux 4.0.4-303.fc22.x86_64 | 2026-03-03 18:29 |
-+-----+----------------+-------+-----------------------------+------------------+
-
- - +

Top 3 Boots's by Host

+

Boots is the total number of host boots over the entire lifespan.

+ + + + + +
PosHostBootsLast KernelUpdated
1. alphacentauri671FreeBSD 11.4-RELEASE-p72026-03-03 18:29
2. mars207Linux 3.2.0-4-amd642026-03-03 18:29
3. callisto153Linux 4.0.4-303.fc22.x86_642026-03-03 18:29
diff --git a/fixtures/Host.Downtime.HTML.expected b/fixtures/Host.Downtime.HTML.expected index 020f638..217681c 100644 --- a/fixtures/Host.Downtime.HTML.expected +++ b/fixtures/Host.Downtime.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Downtime's by Host - - -

Top 3 Downtime's by Host


-
-Downtime is the total downtime of a host over the entire lifespan.
-
-
+-----+----------------+-----------------------------+--------------------------+------------------+
-| Pos |           Host |                    Downtime |              Last Kernel |          Updated |
-+-----+----------------+-----------------------------+--------------------------+------------------+
-|  1. |       dionysus |  8 years, 3 months, 16 days | FreeBSD 13.0-RELEASE-p11 | 2026-03-03 18:29 |
-|  2. |  alphacentauri | 5 years, 11 months, 18 days |  FreeBSD 11.4-RELEASE-p7 | 2026-03-03 18:29 |
-|  3. |         uranus |  3 years, 3 months, 28 days |    Linux 5.16.14-arch1-1 | 2026-03-03 18:29 |
-+-----+----------------+-----------------------------+--------------------------+------------------+
-
- - +

Top 3 Downtime's by Host

+

Downtime is the total downtime of a host over the entire lifespan.

+ + + + + +
PosHostDowntimeLast KernelUpdated
1. dionysus8 years, 3 months, 16 daysFreeBSD 13.0-RELEASE-p112026-03-03 18:29
2. alphacentauri5 years, 11 months, 18 daysFreeBSD 11.4-RELEASE-p72026-03-03 18:29
3. uranus3 years, 3 months, 28 daysLinux 5.16.14-arch1-12026-03-03 18:29
diff --git a/fixtures/Host.Lifespan.HTML.expected b/fixtures/Host.Lifespan.HTML.expected index a73bc82..b380381 100644 --- a/fixtures/Host.Lifespan.HTML.expected +++ b/fixtures/Host.Lifespan.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Lifespan's by Host - - -

Top 3 Lifespan's by Host


-
-Lifespan is the total uptime + the total downtime of a host.
-
-
+-----+----------------+----------------------------+--------------------------+------------------+
-| Pos |           Host |                   Lifespan |              Last Kernel |          Updated |
-+-----+----------------+----------------------------+--------------------------+------------------+
-|  1. |       dionysus | 8 years, 6 months, 17 days | FreeBSD 13.0-RELEASE-p11 | 2026-03-03 18:29 |
-|  2. |         uranus | 7 years, 2 months, 16 days |    Linux 5.16.14-arch1-1 | 2026-03-03 18:29 |
-|  3. |  alphacentauri | 6 years, 9 months, 13 days |  FreeBSD 11.4-RELEASE-p7 | 2026-03-03 18:29 |
-+-----+----------------+----------------------------+--------------------------+------------------+
-
- - +

Top 3 Lifespan's by Host

+

Lifespan is the total uptime + the total downtime of a host.

+ + + + + +
PosHostLifespanLast KernelUpdated
1. dionysus8 years, 6 months, 17 daysFreeBSD 13.0-RELEASE-p112026-03-03 18:29
2. uranus7 years, 2 months, 16 daysLinux 5.16.14-arch1-12026-03-03 18:29
3. alphacentauri6 years, 9 months, 13 daysFreeBSD 11.4-RELEASE-p72026-03-03 18:29
diff --git a/fixtures/Host.Score.HTML.expected b/fixtures/Host.Score.HTML.expected index c13e4a6..7b7d33f 100644 --- a/fixtures/Host.Score.HTML.expected +++ b/fixtures/Host.Score.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Score's by Host - - -

Top 3 Score's by Host


-
-Score is calculated by combining all other metrics.
-
-
+-----+---------+-------+-----------------------------------+------------------+
-| Pos |    Host | Score |                       Last Kernel |          Updated |
-+-----+---------+-------+-----------------------------------+------------------+
-|  1. |  uranus |   309 |             Linux 5.16.14-arch1-1 | 2026-03-03 18:29 |
-|  2. |  vulcan |   270 | Linux 3.10.0-1160.81.1.el7.x86_64 | 2026-03-03 18:29 |
-|  3. |     sun |   238 |          FreeBSD 10.3-RELEASE-p24 | 2026-03-03 18:29 |
-+-----+---------+-------+-----------------------------------+------------------+
-
- - +

Top 3 Score's by Host

+

Score is calculated by combining all other metrics.

+ + + + + +
PosHostScoreLast KernelUpdated
1. uranus309Linux 5.16.14-arch1-12026-03-03 18:29
2. vulcan270Linux 3.10.0-1160.81.1.el7.x86_642026-03-03 18:29
3. sun238FreeBSD 10.3-RELEASE-p242026-03-03 18:29
diff --git a/fixtures/Host.Uptime.HTML.expected b/fixtures/Host.Uptime.HTML.expected index 7c00ced..e78ebbf 100644 --- a/fixtures/Host.Uptime.HTML.expected +++ b/fixtures/Host.Uptime.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Uptime's by Host - - -

Top 3 Uptime's by Host


-
-Uptime is the total uptime of a host over the entire lifespan.
-
-
+-----+---------+-----------------------------+-----------------------------------+------------------+
-| Pos |    Host |                      Uptime |                       Last Kernel |          Updated |
-+-----+---------+-----------------------------+-----------------------------------+------------------+
-|  1. |  vulcan |   4 years, 4 months, 7 days | Linux 3.10.0-1160.81.1.el7.x86_64 | 2026-03-03 18:29 |
-|  2. |  uranus | 3 years, 11 months, 21 days |             Linux 5.16.14-arch1-1 | 2026-03-03 18:29 |
-|  3. |     sun |  3 years, 9 months, 26 days |          FreeBSD 10.3-RELEASE-p24 | 2026-03-03 18:29 |
-+-----+---------+-----------------------------+-----------------------------------+------------------+
-
- - +

Top 3 Uptime's by Host

+

Uptime is the total uptime of a host over the entire lifespan.

+ + + + + +
PosHostUptimeLast KernelUpdated
1. vulcan4 years, 4 months, 7 daysLinux 3.10.0-1160.81.1.el7.x86_642026-03-03 18:29
2. uranus3 years, 11 months, 21 daysLinux 5.16.14-arch1-12026-03-03 18:29
3. sun3 years, 9 months, 26 daysFreeBSD 10.3-RELEASE-p242026-03-03 18:29
diff --git a/fixtures/Kernel.Boots.HTML.expected b/fixtures/Kernel.Boots.HTML.expected index 273b982..4e23932 100644 --- a/fixtures/Kernel.Boots.HTML.expected +++ b/fixtures/Kernel.Boots.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Boots's by Kernel - - -

Top 3 Boots's by Kernel


-
-Boots is the total number of host boots over the entire lifespan.
-
-
+-----+------------------------------+-------+
-| Pos |                       Kernel | Boots |
-+-----+------------------------------+-------+
-|  1. |          Linux 3.2.0-4-amd64 |   321 |
-|  2. |  Linux 4.0.4-303.fc22.x86_64 |   103 |
-|  3. |         FreeBSD 10.1-RELEASE |    76 |
-+-----+------------------------------+-------+
-
- - +

Top 3 Boots's by Kernel

+

Boots is the total number of host boots over the entire lifespan.

+ + + + + +
PosKernelBoots
1. Linux 3.2.0-4-amd64321
2. Linux 4.0.4-303.fc22.x86_64103
3. FreeBSD 10.1-RELEASE76
diff --git a/fixtures/Kernel.Score.HTML.expected b/fixtures/Kernel.Score.HTML.expected index fcf8e3c..01d0888 100644 --- a/fixtures/Kernel.Score.HTML.expected +++ b/fixtures/Kernel.Score.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Score's by Kernel - - -

Top 3 Score's by Kernel


-
-Score is calculated by combining all other metrics.
-
-
+-----+------------------------------------+-------+
-| Pos |                             Kernel | Score |
-+-----+------------------------------------+-------+
-|  1. |                Linux 3.2.0-4-amd64 |   241 |
-|  2. |  Linux 3.10.0-1160.15.2.el7.x86_64 |   123 |
-|  3. |   Linux 3.10.0-957.21.3.el7.x86_64 |    96 |
-+-----+------------------------------------+-------+
-
- - +

Top 3 Score's by Kernel

+

Score is calculated by combining all other metrics.

+ + + + + +
PosKernelScore
1. Linux 3.2.0-4-amd64241
2. Linux 3.10.0-1160.15.2.el7.x86_64123
3. Linux 3.10.0-957.21.3.el7.x86_6496
diff --git a/fixtures/Kernel.Uptime.HTML.expected b/fixtures/Kernel.Uptime.HTML.expected index a374352..ce9d94a 100644 --- a/fixtures/Kernel.Uptime.HTML.expected +++ b/fixtures/Kernel.Uptime.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Uptime's by Kernel - - -

Top 3 Uptime's by Kernel


-
-Uptime is the total uptime of a host over the entire lifespan.
-
-
+-----+------------------------------------+-----------------------------+
-| Pos |                             Kernel |                      Uptime |
-+-----+------------------------------------+-----------------------------+
-|  1. |                Linux 3.2.0-4-amd64 |  3 years, 5 months, 23 days |
-|  2. |  Linux 3.10.0-1160.15.2.el7.x86_64 | 1 years, 12 months, 15 days |
-|  3. |   Linux 3.10.0-957.21.3.el7.x86_64 |  1 years, 7 months, 13 days |
-+-----+------------------------------------+-----------------------------+
-
- - +

Top 3 Uptime's by Kernel

+

Uptime is the total uptime of a host over the entire lifespan.

+ + + + + +
PosKernelUptime
1. Linux 3.2.0-4-amd643 years, 5 months, 23 days
2. Linux 3.10.0-1160.15.2.el7.x86_641 years, 12 months, 15 days
3. Linux 3.10.0-957.21.3.el7.x86_641 years, 7 months, 13 days
diff --git a/fixtures/KernelMajor.Boots.HTML.expected b/fixtures/KernelMajor.Boots.HTML.expected index 55e626a..c54c058 100644 --- a/fixtures/KernelMajor.Boots.HTML.expected +++ b/fixtures/KernelMajor.Boots.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Boots's by KernelMajor - - -

Top 3 Boots's by KernelMajor


-
-Boots is the total number of host boots over the entire lifespan.
-
-
+-----+----------------+-------+
-| Pos |    KernelMajor | Boots |
-+-----+----------------+-------+
-|  1. |  FreeBSD 10... |   551 |
-|  2. |     Linux 3... |   410 |
-|  3. |     Linux 5... |   249 |
-+-----+----------------+-------+
-
- - +

Top 3 Boots's by KernelMajor

+

Boots is the total number of host boots over the entire lifespan.

+ + + + + +
PosKernelMajorBoots
1. FreeBSD 10...551
2. Linux 3...410
3. Linux 5...249
diff --git a/fixtures/KernelMajor.Score.HTML.expected b/fixtures/KernelMajor.Score.HTML.expected index ab5b6a6..116f74d 100644 --- a/fixtures/KernelMajor.Score.HTML.expected +++ b/fixtures/KernelMajor.Score.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Score's by KernelMajor - - -

Top 3 Score's by KernelMajor


-
-Score is calculated by combining all other metrics.
-
-
+-----+----------------+-------+
-| Pos |    KernelMajor | Score |
-+-----+----------------+-------+
-|  1. |     Linux 3... |   736 |
-|  2. |  FreeBSD 10... |   406 |
-|  3. |     Linux 5... |   268 |
-+-----+----------------+-------+
-
- - +

Top 3 Score's by KernelMajor

+

Score is calculated by combining all other metrics.

+ + + + + +
PosKernelMajorScore
1. Linux 3...736
2. FreeBSD 10...406
3. Linux 5...268
diff --git a/fixtures/KernelMajor.Uptime.HTML.expected b/fixtures/KernelMajor.Uptime.HTML.expected index dd08ee3..848e2ff 100644 --- a/fixtures/KernelMajor.Uptime.HTML.expected +++ b/fixtures/KernelMajor.Uptime.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Uptime's by KernelMajor - - -

Top 3 Uptime's by KernelMajor


-
-Uptime is the total uptime of a host over the entire lifespan.
-
-
+-----+----------------+-----------------------------+
-| Pos |    KernelMajor |                      Uptime |
-+-----+----------------+-----------------------------+
-|  1. |     Linux 3... | 11 years, 2 months, 11 days |
-|  2. |  FreeBSD 10... |   5 years, 9 months, 9 days |
-|  3. |     Linux 5... |  3 years, 12 months, 2 days |
-+-----+----------------+-----------------------------+
-
- - +

Top 3 Uptime's by KernelMajor

+

Uptime is the total uptime of a host over the entire lifespan.

+ + + + + +
PosKernelMajorUptime
1. Linux 3...11 years, 2 months, 11 days
2. FreeBSD 10...5 years, 9 months, 9 days
3. Linux 5...3 years, 12 months, 2 days
diff --git a/fixtures/KernelName.Boots.HTML.expected b/fixtures/KernelName.Boots.HTML.expected index 6685f18..e984d77 100644 --- a/fixtures/KernelName.Boots.HTML.expected +++ b/fixtures/KernelName.Boots.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Boots's by KernelName - - -

Top 3 Boots's by KernelName


-
-Boots is the total number of host boots over the entire lifespan.
-
-
+-----+------------+-------+
-| Pos | KernelName | Boots |
-+-----+------------+-------+
-|  1. |    FreeBSD |   872 |
-|  2. |      Linux |   867 |
-|  3. |    OpenBSD |    44 |
-+-----+------------+-------+
-
- - +

Top 3 Boots's by KernelName

+

Boots is the total number of host boots over the entire lifespan.

+ + + + + +
PosKernelNameBoots
1. FreeBSD872
2. Linux867
3. OpenBSD44
diff --git a/fixtures/KernelName.Score.HTML.expected b/fixtures/KernelName.Score.HTML.expected index 1f1a665..79fd8b9 100644 --- a/fixtures/KernelName.Score.HTML.expected +++ b/fixtures/KernelName.Score.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Score's by KernelName - - -

Top 3 Score's by KernelName


-
-Score is calculated by combining all other metrics.
-
-
+-----+------------+-------+
-| Pos | KernelName | Score |
-+-----+------------+-------+
-|  1. |      Linux |  1292 |
-|  2. |    FreeBSD |   700 |
-|  3. |    OpenBSD |   196 |
-+-----+------------+-------+
-
- - +

Top 3 Score's by KernelName

+

Score is calculated by combining all other metrics.

+ + + + + +
PosKernelNameScore
1. Linux1292
2. FreeBSD700
3. OpenBSD196
diff --git a/fixtures/KernelName.Uptime.HTML.expected b/fixtures/KernelName.Uptime.HTML.expected index 345b33f..353b63f 100644 --- a/fixtures/KernelName.Uptime.HTML.expected +++ b/fixtures/KernelName.Uptime.HTML.expected @@ -1,23 +1,8 @@ - - - - - - -Top 3 Uptime's by KernelName - - -

Top 3 Uptime's by KernelName


-
-Uptime is the total uptime of a host over the entire lifespan.
-
-
+-----+------------+-----------------------------+
-| Pos | KernelName |                      Uptime |
-+-----+------------+-----------------------------+
-|  1. |      Linux | 19 years, 4 months, 18 days |
-|  2. |    FreeBSD | 9 years, 11 months, 29 days |
-|  3. |    OpenBSD |  3 years, 1 months, 18 days |
-+-----+------------+-----------------------------+
-
- - +

Top 3 Uptime's by KernelName

+

Uptime is the total uptime of a host over the entire lifespan.

+ + + + + +
PosKernelNameUptime
1. Linux19 years, 4 months, 18 days
2. FreeBSD9 years, 11 months, 29 days
3. OpenBSD3 years, 1 months, 18 days
diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 44f9888..5d642b6 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -312,7 +312,7 @@ func TestReportHTTPTable(t *testing.T) { query: "OutputFormat=HTML&limit=2", wantCode: http.StatusOK, wantCTPfx: "text/html", - bodyNeedle: []string{"", "
"},
+			bodyNeedle: []string{"", ""},
 		},
 		{
 			name:      "gemtext",
diff --git a/internal/goprecords/report.go b/internal/goprecords/report.go
index 12c3951..8916caa 100644
--- a/internal/goprecords/report.go
+++ b/internal/goprecords/report.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"io"
 	"sort"
+	"strings"
 )
 
 type metricExtractor struct {
@@ -61,38 +62,33 @@ func WriteReports(w io.Writer, aggregates *Aggregates, cfg ReportConfig) error {
 		if cfg.Category != CategoryHost && (cfg.Metric == MetricDowntime || cfg.Metric == MetricLifespan) {
 			return fmt.Errorf("Category %s only supports: Boots, Uptime, Score", cfg.Category)
 		}
-		if cfg.Category == CategoryHost {
-			if err := writeReportString(w, NewHostReporter(aggregates, cfg.Limit, cfg.Metric, cfg.OutputFormat, 1).Report()); err != nil {
-				return err
-			}
-		} else {
-			if err := writeReportString(w, NewReporter(aggregates, cfg.Category, cfg.Limit, cfg.Metric, cfg.OutputFormat, 1).Report()); err != nil {
-				return err
-			}
-		}
-		return nil
+		s := reportForPair(aggregates, cfg.Category, cfg.Metric, cfg.Limit, 1, cfg.OutputFormat)
+		return writeReportString(w, wrapIfHTML(s, cfg.OutputFormat))
 	}
 	order, err := StatsOrderList(cfg.StatsOrder)
 	if err != nil {
 		return err
 	}
 	headerIndent := uint(2)
-	for _, pair := range order {
-		c, m := pair.Category, pair.Metric
-		if !cfg.IncludeKernel && c == CategoryKernel {
-			continue
+	if cfg.OutputFormat == FormatHTML {
+		var parts []string
+		for _, pair := range order {
+			if skipPair(cfg, pair.Category, pair.Metric) {
+				continue
+			}
+			if s := reportForPair(aggregates, pair.Category, pair.Metric, cfg.Limit, headerIndent, cfg.OutputFormat); s != "" {
+				parts = append(parts, s)
+			}
 		}
-		if c != CategoryHost && (m == MetricDowntime || m == MetricLifespan) {
+		return writeReportString(w, wrapHTMLDocument(strings.Join(parts, "\n")))
+	}
+	for _, pair := range order {
+		if skipPair(cfg, pair.Category, pair.Metric) {
 			continue
 		}
-		if c == CategoryHost {
-			if err := writeReportString(w, NewHostReporter(aggregates, cfg.Limit, m, cfg.OutputFormat, headerIndent).Report()); err != nil {
-				return err
-			}
-		} else {
-			if err := writeReportString(w, NewReporter(aggregates, c, cfg.Limit, m, cfg.OutputFormat, headerIndent).Report()); err != nil {
-				return err
-			}
+		s := reportForPair(aggregates, pair.Category, pair.Metric, cfg.Limit, headerIndent, cfg.OutputFormat)
+		if err := writeReportString(w, s); err != nil {
+			return err
 		}
 		if err := writeReportString(w, "\n"); err != nil {
 			return err
@@ -101,6 +97,96 @@ func WriteReports(w io.Writer, aggregates *Aggregates, cfg ReportConfig) error {
 	return nil
 }
 
+func reportForPair(aggregates *Aggregates, c Category, m Metric, limit, headerIndent uint, outputFormat OutputFormat) string {
+	if c == CategoryHost {
+		return NewHostReporter(aggregates, limit, m, outputFormat, headerIndent).Report()
+	}
+	return NewReporter(aggregates, c, limit, m, outputFormat, headerIndent).Report()
+}
+
+func skipPair(cfg ReportConfig, c Category, m Metric) bool {
+	if !cfg.IncludeKernel && c == CategoryKernel {
+		return true
+	}
+	if c != CategoryHost && (m == MetricDowntime || m == MetricLifespan) {
+		return true
+	}
+	return false
+}
+
+func wrapIfHTML(s string, f OutputFormat) string {
+	if f != FormatHTML {
+		return s
+	}
+	return wrapHTMLDocument(s)
+}
+
+func wrapHTMLDocument(body string) string {
+	var b strings.Builder
+	b.WriteString("\n\n\n")
+	b.WriteString("\n")
+	b.WriteString("\n")
+	b.WriteString("goprecords uptime report\n")
+	b.WriteString(htmlStyle)
+	b.WriteString("\n\n")
+	b.WriteString(body)
+	b.WriteString("\n\n")
+	return b.String()
+}
+
+const htmlStyle = `
+`
+
 func writeReportString(w io.Writer, s string) error {
 	_, err := io.WriteString(w, s)
 	return err
diff --git a/internal/goprecords/report_format.go b/internal/goprecords/report_format.go
index 8d06b04..079fe94 100644
--- a/internal/goprecords/report_format.go
+++ b/internal/goprecords/report_format.go
@@ -21,22 +21,6 @@ func (r reportBuilder) formatReport(rows []tableRow, hasLastKernel, hasLastUpdat
 }
 
 func (r reportBuilder) formatReportHTML(rows []tableRow, hasLastKernel, hasLastUpdated bool) string {
-	cW, nW, vW, lkW, luW := r.reportWidths(rows, hasLastKernel, hasLastUpdated)
-	border := r.buildBorder(cW, nW, vW, lkW, luW, hasLastKernel, hasLastUpdated)
-	fmtStr := r.buildFormatStr(cW, nW, vW, lkW, luW, hasLastKernel, hasLastUpdated)
-	var headRow string
-	if hasLastKernel && hasLastUpdated {
-		headRow = fmt.Sprintf(fmtStr+"\n", "Pos", r.category.String(), r.metric.String(), "Last Kernel", "Updated")
-	} else if hasLastKernel {
-		headRow = fmt.Sprintf(fmtStr+"\n", "Pos", r.category.String(), r.metric.String(), "Last Kernel")
-	} else if hasLastUpdated {
-		headRow = fmt.Sprintf(fmtStr+"\n", "Pos", r.category.String(), r.metric.String(), "Updated")
-	} else {
-		headRow = fmt.Sprintf(fmtStr+"\n", "Pos", r.category.String(), r.metric.String())
-	}
-	body := r.buildReportBody(rows, fmtStr, hasLastKernel, hasLastUpdated)
-	ascii := border + headRow + border + body + border
-
 	hl := int(r.headerIndent)
 	if hl < 1 {
 		hl = 1
@@ -46,27 +30,54 @@ func (r reportBuilder) formatReportHTML(rows []tableRow, hasLastKernel, hasLastU
 	}
 	title := fmt.Sprintf("Top %d %s's by %s", r.limit, r.metric, r.category)
 	desc := MetricDescription(r.metric)
+	htag := strconv.Itoa(hl)
 
 	var b strings.Builder
-	b.WriteString("\n\n\n\n")
-	b.WriteString("\n")
-	b.WriteString("\n")
-	b.WriteString(template.HTMLEscapeString(title))
-	b.WriteString("\n\n\n")
+	b.WriteString("")
 	b.WriteString(template.HTMLEscapeString(title))
 	b.WriteString("
\n
\n") + b.WriteString(htag) + b.WriteString(">\n") if desc != "" { - b.WriteString("") + b.WriteString("

") b.WriteString(template.HTMLEscapeString(desc)) - b.WriteString("
\n
\n") + b.WriteString("

\n") + } + b.WriteString("
\n") + if hasLastKernel { + b.WriteString("") + } + if hasLastUpdated { + b.WriteString("") + } + b.WriteString("\n") + for _, row := range rows { + b.WriteString("") + if hasLastKernel { + b.WriteString("") + } + if hasLastUpdated { + b.WriteString("") + } + b.WriteString("\n") } - b.WriteString("
")
-	b.WriteString(template.HTMLEscapeString(ascii))
-	b.WriteString("
\n\n\n") + b.WriteString("
Pos") + b.WriteString(template.HTMLEscapeString(r.category.String())) + b.WriteString("") + b.WriteString(template.HTMLEscapeString(r.metric.String())) + b.WriteString("Last KernelUpdated
") + b.WriteString(template.HTMLEscapeString(row.Pos)) + b.WriteString("") + b.WriteString(template.HTMLEscapeString(row.Name)) + b.WriteString("") + b.WriteString(template.HTMLEscapeString(row.Value)) + b.WriteString("") + b.WriteString(template.HTMLEscapeString(row.LastKernel)) + b.WriteString("") + b.WriteString(template.HTMLEscapeString(row.LastUpdated)) + b.WriteString("
\n") return b.String() } diff --git a/internal/goprecords/report_test.go b/internal/goprecords/report_test.go index fccb0d2..962afdb 100644 --- a/internal/goprecords/report_test.go +++ b/internal/goprecords/report_test.go @@ -114,8 +114,8 @@ func TestReportHTML(t *testing.T) { t.Fatalf("expected HTMLReporter, got %T", reporter) } report := reporter.Report() - if !strings.Contains(report, "") || !strings.Contains(report, "
") {
-		t.Fatalf("expected HTML document with pre, got %q", report)
+	if !strings.Contains(report, "") || !strings.Contains(report, "

") { + t.Fatalf("expected HTML fragment with table, got %q", report) } if !strings.Contains(report, "host1") { t.Error("expected report to contain host1") diff --git a/internal/version/version.go b/internal/version/version.go index 7ee9a7c..1b13709 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,4 +1,4 @@ package version // Tag is the application release version. -const Tag = "0.5.2" +const Tag = "0.5.3" -- cgit v1.2.3