diff options
| author | s <[email protected]> | 2025-12-20 03:46:40 -0500 |
|---|---|---|
| committer | s <[email protected]> | 2025-12-20 03:46:40 -0500 |
| commit | 542a09fd14761b4789ae89e16060b1b453e2e0f2 (patch) | |
| tree | cd302e6e4be3544658bbf31d4ba0417dad6126ab /internal/formatter/formatter.go | |
| parent | bfd971bbc8d35685f18f4b9dd3a52f04f8b4f77f (diff) | |
| download | dborg-1.0.10.tar.gz dborg-1.0.10.zip | |
feat: add dynamic terminal width detection for improved formattingv1.0.10
Diffstat (limited to 'internal/formatter/formatter.go')
| -rw-r--r-- | internal/formatter/formatter.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/internal/formatter/formatter.go b/internal/formatter/formatter.go index 4d65c60..bb36fa8 100644 --- a/internal/formatter/formatter.go +++ b/internal/formatter/formatter.go @@ -10,6 +10,7 @@ import ( "text/tabwriter" "git.db.org.ai/dborg/internal/utils" + "golang.org/x/term" ) const ( @@ -71,7 +72,14 @@ func isTerminal() bool { } func GetTerminalWidth() int { - return 80 + if !isTerminal() { + return 80 + } + width, _, err := term.GetSize(int(os.Stdout.Fd())) + if err != nil || width <= 0 { + return 80 + } + return width } func Colorize(text string, color string) string { @@ -323,10 +331,11 @@ func PrintSection(title string) { } func PrintDivider() { + width := GetTerminalWidth() if isTerminal() { - fmt.Println(Dim(strings.Repeat("─", 80))) + fmt.Println(Dim(strings.Repeat("─", width))) } else { - fmt.Println(strings.Repeat("-", 80)) + fmt.Println(strings.Repeat("-", width)) } } |
