Skip to content

Commit 6f6cefa

Browse files
committed
Drop the unused HeaderHeight constant and dedupe the header config build
Follow-up to review feedback on the shared-header redesign: - Remove the HeaderHeight constant. Nothing referenced it (callers compute height via HeaderHeightFor), and its doc described a "maximum" that HeaderHeightFor does not actually enforce, so the comment was misleading. - In the view and modify View() methods, build the header config once and reuse it for both RenderHeader and the height reservation instead of rebuilding it twice per frame. The click/scroll handlers keep deriving the height from the same config, so the header's dimensions remain a single source of truth.
1 parent a14cb55 commit 6f6cefa

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

internal/tui/modifyview/model.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,8 +1361,13 @@ func (m Model) View() string {
13611361

13621362
// Header
13631363
showHeader := shared.ShouldShowHeader(m.width, m.height)
1364+
headerLines := 0
13641365
if showHeader {
1365-
shared.RenderHeader(&out, m.buildHeaderConfig(), m.width, m.height)
1366+
// Build the header config once and reuse it for both rendering and the
1367+
// height reservation, so View does not rebuild it twice per frame.
1368+
cfg := m.buildHeaderConfig()
1369+
shared.RenderHeader(&out, cfg, m.width, m.height)
1370+
headerLines = shared.HeaderHeightFor(cfg)
13661371
} else {
13671372
// The header (and its inline-image logo) is hidden; clear any logo that
13681373
// was previously drawn so it does not linger in the graphics layer.
@@ -1392,7 +1397,7 @@ func (m Model) View() string {
13921397
bottomLines := 2 // error/status line + status bar (post-scroll newline is inline)
13931398

13941399
// Scrolling — reserve space for header and fixed bottom
1395-
reservedLines := bottomLines + m.headerHeight()
1400+
reservedLines := bottomLines + headerLines
13961401
viewHeight := m.height - reservedLines
13971402
if viewHeight < 1 {
13981403
viewHeight = 1

internal/tui/shared/header.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import (
66
"github.com/charmbracelet/lipgloss"
77
)
88

9-
// HeaderHeight is the maximum number of lines the header occupies (a top border,
10-
// the content rows, and a bottom border). The actual height for a given config
11-
// is HeaderHeightFor, which sizes the box to its content with no trailing empty
12-
// rows.
13-
const HeaderHeight = 9
14-
159
// MinHeightForHeader is the minimum terminal height to show the header.
1610
const MinHeightForHeader = 25
1711

internal/tui/stackview/model.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,13 @@ func (m Model) View() string {
360360
var out strings.Builder
361361

362362
showHeader := shared.ShouldShowHeader(m.width, m.height)
363+
reservedLines := 0
363364
if showHeader {
364-
shared.RenderHeader(&out, m.buildHeaderConfig(), m.width, m.height)
365+
// Build the header config once and reuse it for both rendering and the
366+
// height reservation, so View does not rebuild it twice per frame.
367+
cfg := m.buildHeaderConfig()
368+
shared.RenderHeader(&out, cfg, m.width, m.height)
369+
reservedLines = shared.HeaderHeightFor(cfg)
365370
} else {
366371
// The header (and its inline-image logo) is hidden; clear any logo that
367372
// was previously drawn so it does not linger in the graphics layer.
@@ -392,7 +397,6 @@ func (m Model) View() string {
392397
content := b.String()
393398

394399
// Apply scrolling
395-
reservedLines := m.headerHeight()
396400
viewHeight := m.height - reservedLines
397401
if viewHeight < 1 {
398402
viewHeight = 1

0 commit comments

Comments
 (0)