Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/templates/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,12 +941,15 @@ func renderSingleColumnLines(p *Panel, row PanelRow, inner int, isFirst, isLast
// WrapWidth < 0 disables wrapping entirely for this row.
// WrapWidth > 0 uses that as the explicit wrap width.
// WrapWidth == 0 falls back to the panel's target width.
// If your wrap is greater than visible width it is adjusted.
effectiveWrap := row.WrapWidth
visibleWidth := inner - lw - 1
if effectiveWrap == 0 && p.width > 0 {
availForValue := inner - lw - 1
if availForValue > 0 {
effectiveWrap = availForValue
if visibleWidth > 0 {
effectiveWrap = visibleWidth
}
} else if effectiveWrap > visibleWidth {
effectiveWrap = visibleWidth
}

var chunks []string
Expand Down
24 changes: 24 additions & 0 deletions internal/templates/panel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,30 @@ func TestRenderPanel_AllLinesEqualVisualWidth(t *testing.T) {
}
}

func TestRenderPanel_AllLinesFitInsideWidth(t *testing.T) {
p := makePanel("x", "X", 20, borderFull, []PanelRow{
{FullLabel: "Short:", ShortLabel: "S:", Value: "This is a short description."},
{FullLabel: "HowItBe:", ShortLabel: "HIB:", Value: "This is an extremely long line of text. It is unnecessarily long. There's no reason for it to be this long, but we want to make sure wrapping is working correctly, so I will continue to make this line longer as necessary to get back good testing data."},
})
got := renderPanel(p)
for i, line := range got {
assert.LessOrEqual(t, panelVisualWidth(line), p.width, "line %d is longer than panel width", i)
}
}

func TestRenderPanel_AllLinesFitInsideWidthWithMismatchedWrap(t *testing.T) {
p := makePanel("x", "X", 20, borderFull, []PanelRow{
{FullLabel: "Short:", ShortLabel: "S:", Value: "This is a short description."},
{FullLabel: "HowItBe:", ShortLabel: "HIB:", WrapWidth: 50, Value: "This is an extremely long line of text. It is unnecessarily long. There's no reason for it to be this long, but we want to make sure wrapping is working correctly, so I will continue to make this line longer as necessary to get back good testing data."},
{FullLabel: "HowItBe:", ShortLabel: "HIB:", WrapWidth: 15, Value: "This is an extremely long line of text. It is unnecessarily long. There's no reason for it to be this long, but we want to make sure wrapping is working correctly, so I will continue to make this line longer as necessary to get back good testing data."},
{FullLabel: "HowItBe:", ShortLabel: "HIB:", WrapWidth: 20, Value: "This is an extremely long line of text. It is unnecessarily long. There's no reason for it to be this long, but we want to make sure wrapping is working correctly, so I will continue to make this line longer as necessary to get back good testing data."},
})
got := renderPanel(p)
for i, line := range got {
assert.LessOrEqual(t, panelVisualWidth(line), p.width, "line %d is longer than panel width", i)
}
}

func TestRenderPanel_AnsiTagsDoNotAffectWidth(t *testing.T) {
p := makePanel("x", "X", 19, borderFull, []PanelRow{
{FullLabel: `<ansi fg="yellow">Name:</ansi>`, ShortLabel: "N:", Value: `<ansi fg="green">Alice</ansi>`},
Expand Down