Skip to content

Commit

Permalink
Use terminal width for Minder output (#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
evankanderson authored Dec 11, 2023
1 parent ed49b67 commit 7acaf81
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions internal/util/cli/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
package cli

import (
"os"

"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/lipgloss"
"golang.org/x/term"
)

// Color Palette
Expand All @@ -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).
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 7acaf81

Please # to comment.