Skip to content

Commit ca293d1

Browse files
authored
Fix height calculations (#58)
1 parent 753d6ea commit ca293d1

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

ui/model.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9292
m.help.Width = msg.Width
9393
m.width = msg.Width
9494
m.height = msg.Height
95-
log.Printf("model: WindowSizeMsg: h=%v", msg.Height)
9695

96+
headerHeight := lipgloss.Height(header())
97+
footerHeight := lipgloss.Height(m.help.View())
98+
msg.Height = msg.Height - (headerHeight + footerHeight)
9799
m.updateAllModels(msg)
100+
101+
log.Printf("WindowSizeMsg: full: h=%d, w=%d. mainView: h=%d, w=%d", m.height, msg.Width, msg.Height, msg.Width)
102+
98103
return m, m.refresh()
99104

100105
case tea.KeyMsg:

ui/pager.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,14 @@ func (p *pager) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6363
}
6464
case tea.WindowSizeMsg:
6565
p.width = msg.Width
66-
headerHeight := lipgloss.Height(header())
67-
verticalMarginHeight := headerHeight + footerHeight
68-
log.Printf("pager(%s): WindowSizeMsg: h=%v, headerHeight=%v, footerHeight=%v, verticalMarginHeight=%v", p.name, msg.Height, headerHeight, footerHeight, verticalMarginHeight)
6966
if !p.ready {
7067
log.Printf("pager(%s): not-ready. height=%v, ypos=%v", p.name, p.viewport.Height, p.viewport.YPosition)
71-
p.viewport = viewport.New(msg.Width, msg.Height-verticalMarginHeight)
72-
p.viewport.YPosition = headerHeight
68+
p.viewport = viewport.New(msg.Width, msg.Height)
7369
p.ready = true
7470
} else {
7571
p.viewport.Width = msg.Width
76-
p.viewport.Height = msg.Height - verticalMarginHeight
72+
p.viewport.Height = msg.Height
7773
}
78-
// case pagerLoading:
79-
// p.viewport.SetContent("\n Loading...")
8074

8175
case tea.KeyMsg:
8276
switch {

ui/table.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/charmbracelet/bubbles/spinner"
77
"github.com/charmbracelet/bubbles/table"
88
tea "github.com/charmbracelet/bubbletea"
9-
"github.com/charmbracelet/lipgloss"
109
)
1110

1211
type TableData interface {
@@ -57,13 +56,12 @@ func (t *Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5756
}
5857
case tea.WindowSizeMsg:
5958
tableWidth := percent(msg.Width, 100)
60-
headerHeight := lipgloss.Height(header())
61-
verticalMarginHeight := headerHeight + footerHeight
62-
tableHeight := msg.Height - verticalMarginHeight - 3
63-
log.Printf("table: height=%v, tableHeight=%v, verticalMarginHeight=%v", msg.Height, tableHeight, verticalMarginHeight)
59+
tableHeight := msg.Height - 3
60+
log.Printf("table: height=%v, tableHeight=%v", msg.Height, tableHeight)
6461

6562
t.SetWidth(tableWidth)
66-
t.SetHeight(tableHeight)
63+
t.height = tableHeight
64+
t.Model.SetHeight(tableHeight)
6765

6866
case tea.KeyMsg:
6967
switch msg.String() {
@@ -109,11 +107,6 @@ func (t *Table) SetWidth(width int) {
109107
t.Model.SetWidth(width)
110108
}
111109

112-
func (t *Table) SetHeight(height int) {
113-
t.height = height
114-
t.Model.SetHeight(height)
115-
}
116-
117110
func (t *Table) SetColumns(firstRow table.Row) {
118111
if len(t.columnPercentages) != len(firstRow) {
119112
panic("length not equal")

ui/ui.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
const (
14-
footerHeight = 3
14+
footerHeight = 2
1515
)
1616

1717
var Version string

0 commit comments

Comments
 (0)