Skip to content

Commit 4fe2e56

Browse files
committed
fix form component alignment issues
1 parent 272c6d1 commit 4fe2e56

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

pkg/tui/components/form/checkbox.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"strings"
55

66
tea "github.com/charmbracelet/bubbletea"
7-
"github.com/charmbracelet/lipgloss"
87

98
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/theme"
109
)
@@ -90,7 +89,8 @@ func (c *CheckboxField) View() string {
9089
b.WriteString(" " + styles.Hint.Render(c.spec.Help))
9190
b.WriteString("\n")
9291
}
93-
return lipgloss.NewStyle().MarginBottom(1).Render(b.String())
92+
b.WriteString("\n")
93+
return b.String()
9494
}
9595

9696
// Error returns the most recent validation error.

pkg/tui/components/form/select.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"strings"
55

66
tea "github.com/charmbracelet/bubbletea"
7-
"github.com/charmbracelet/lipgloss"
87

98
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/theme"
109
)
@@ -115,7 +114,8 @@ func (s *SelectField) View() string {
115114
b.WriteString(styles.Hint.Render(s.spec.Help))
116115
b.WriteString("\n")
117116
}
118-
return lipgloss.NewStyle().MarginBottom(1).Render(b.String())
117+
b.WriteString("\n")
118+
return b.String()
119119
}
120120

121121
// Error returns the most recent validation error.

pkg/tui/components/form/text.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/charmbracelet/bubbles/textinput"
77
tea "github.com/charmbracelet/bubbletea"
8-
"github.com/charmbracelet/lipgloss"
98

109
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/theme"
1110
)
@@ -84,7 +83,8 @@ func (t *TextField) View() string {
8483
b.WriteString(styles.Hint.Render(t.spec.Help))
8584
b.WriteString("\n")
8685
}
87-
return lipgloss.NewStyle().MarginBottom(1).Render(b.String())
86+
b.WriteString("\n")
87+
return b.String()
8888
}
8989

9090
// Error returns the most recent validation error message.
@@ -102,11 +102,18 @@ func (t *TextField) Validate() error {
102102
return nil
103103
}
104104

105-
// SetWidth hints the input width.
105+
// SetWidth hints the input width. bubbles/textinput pads the value with
106+
// trailing spaces up to Width, so we cap it to avoid painting hundreds of
107+
// columns of padding on wide terminals while still leaving headroom under
108+
// the content area on narrower ones.
106109
func (t *TextField) SetWidth(w int) {
107110
t.width = w
108-
t.input.Width = w - 4
109-
if t.input.Width < 10 {
110-
t.input.Width = 10
111+
width := w - 6
112+
if width > 80 {
113+
width = 80
114+
}
115+
if width < 10 {
116+
width = 10
111117
}
118+
t.input.Width = width
112119
}

0 commit comments

Comments
 (0)