Skip to content

Commit 692dfa0

Browse files
committed
fix: detect terminal width at startup instead of hard-coding 120
Use term.GetSize to read the actual terminal width, falling back to 80. This prevents a brief layout glitch on narrow terminals before the first WindowSizeMsg arrives from bubbletea.
1 parent d480043 commit 692dfa0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/policywizard/model.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package policywizard
22

33
import (
4+
"os"
45
"strings"
56

67
"github.com/charmbracelet/bubbles/spinner"
78
tea "github.com/charmbracelet/bubbletea"
89
"github.com/charmbracelet/huh"
910
"github.com/charmbracelet/lipgloss"
1011
"github.com/kosli-dev/cli/internal/policy"
12+
"golang.org/x/term"
1113
)
1214

1315
const formWidth = 45
@@ -56,13 +58,18 @@ func NewModel(ctx *Context) Model {
5658
startStep = stepLoading
5759
}
5860

61+
w := 80
62+
if tw, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil && tw > 0 {
63+
w = tw
64+
}
65+
5966
m := Model{
6067
step: startStep,
6168
Policy: policy.NewPolicy(),
6269
ctx: ctx,
6370
styles: newStyles(),
6471
spinner: s,
65-
width: 120,
72+
width: w,
6673
}
6774
if startStep != stepLoading {
6875
m.form = m.buildForm()

0 commit comments

Comments
 (0)