From 336e87c199af5e1bf9d62dbb55e2c1b088f5504f Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:14:32 +0200 Subject: [PATCH] Add headers to output when using logs tail --- internal/display/display.go | 11 +++++++++++ internal/display/display_test.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/display/display.go b/internal/display/display.go index 3e059fa4a..b748219f1 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -148,6 +148,17 @@ func (r *Renderer) Stream(data []View, ch <-chan View) { } } + if len(data) > 0 { + header := []string{ + truncate("TYPE", 23), + truncate("DESCRIPTION", 54), + truncate("DATE", 20), + truncate("CONNECTION", 20), + truncate("CLIENT", 20), + } + displayRow(header) + } + for _, v := range data { displayView(v) } diff --git a/internal/display/display_test.go b/internal/display/display_test.go index 55d3eba68..2a0f8e64d 100644 --- a/internal/display/display_test.go +++ b/internal/display/display_test.go @@ -63,7 +63,9 @@ func TestStream(t *testing.T) { t.Run("Stream correctly handles nil channel", func(t *testing.T) { mockRender.Stream(results, nil) - expectedResult := "API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A \n" + expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT +API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A +` assert.Equal(t, expectedResult, stdout.String()) stdout.Reset() }) @@ -93,7 +95,8 @@ func TestStream(t *testing.T) { wg.Wait() - expectedResult := `API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A + expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT +API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A API Operation Update tenant settings Jan 01 00:00:00.000 N/A N/A ` assert.Equal(t, expectedResult, stdout.String())