From 7acaf816f10e10b82ef883268d6f98c6fb9f1d97 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Mon, 11 Dec 2023 12:37:26 -0800 Subject: [PATCH] Use terminal width for Minder output (#1899) --- internal/util/cli/style.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/util/cli/style.go b/internal/util/cli/style.go index 02810294c4..eafb180ba0 100644 --- a/internal/util/cli/style.go +++ b/internal/util/cli/style.go @@ -22,8 +22,11 @@ package cli import ( + "os" + "github.com/charmbracelet/bubbles/table" "github.com/charmbracelet/lipgloss" + "golang.org/x/term" ) // Color Palette @@ -41,12 +44,13 @@ var ( ) const ( - // DefaultBannerWidth is the default width for a banner - DefaultBannerWidth = 100 + keyWidth = 15 ) // Styles var ( + // DefaultBannerWidth is the default width for a banner + DefaultBannerWidth = 80 // Header is the style to use for headers Header = lipgloss.NewStyle(). Bold(true). @@ -98,11 +102,20 @@ var ( Key int Value int }{ - Key: 27, // 30 - 3 for padding - Value: 67, // 70 - 3 for padding + Key: keyWidth, + Value: DefaultBannerWidth - keyWidth - 6, // 6 characters for padding } ) +func init() { + // Get the terminal width, if available, and set widths based on terminal width + w, _, err := term.GetSize(int(os.Stdout.Fd())) + if err == nil { + DefaultBannerWidth = w + KeyValTableWidths.Value = w - keyWidth - 6 + } +} + // TableRender renders a table given a table model func TableRender(t table.Model) string { return Table.Render(t.View())