Skip to content

Commit 8e6f109

Browse files
committed
feat: header
1 parent f5e4c82 commit 8e6f109

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

diffviewer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/charmbracelet/lipgloss"
1414
)
1515

16-
const headerHeight = 3
16+
const dirrHeaderHeight = 3
1717

1818
type diffModel struct {
1919
vp viewport.Model
@@ -54,7 +54,7 @@ func (m diffModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5454
m.width = msg.Width
5555
m.height = msg.Height
5656
m.vp.Width = m.width
57-
m.vp.Height = m.height - headerHeight
57+
m.vp.Height = m.height - dirrHeaderHeight
5858
cmds = append(cmds, diff(m.file, m.width))
5959
}
6060

@@ -96,7 +96,7 @@ func (m diffModel) headerView() string {
9696
return base.
9797
Width(m.width).
9898
PaddingLeft(1).
99-
Height(headerHeight - 1).
99+
Height(dirrHeaderHeight - 1).
100100
BorderStyle(lipgloss.NormalBorder()).
101101
BorderBottom(true).
102102
BorderForeground(lipgloss.Color("8")).

main.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6161
return m, tea.Quit
6262
case "e":
6363
m.isShowingFileTree = !m.isShowingFileTree
64-
df, dfCmd := m.diffViewer.(diffModel).Update(dimensionsMsg{Width: m.width - m.getFileTreeWidth(), Height: m.height - footerHeight})
64+
df, dfCmd := m.diffViewer.(diffModel).Update(dimensionsMsg{Width: m.width - m.getFileTreeWidth(), Height: m.height - footerHeight - headerHeight})
6565
m.diffViewer = df
6666
return m, dfCmd
6767
case "up", "k":
@@ -84,7 +84,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8484
m.help.Width = msg.Width
8585
m.width = msg.Width
8686
m.height = msg.Height
87-
df, dfCmd := m.diffViewer.(diffModel).Update(dimensionsMsg{Width: m.width - m.getFileTreeWidth(), Height: m.height})
87+
df, dfCmd := m.diffViewer.(diffModel).Update(dimensionsMsg{Width: m.width - m.getFileTreeWidth(), Height: m.height - footerHeight - headerHeight})
8888
m.diffViewer = df
8989
cmds = append(cmds, dfCmd)
9090

@@ -113,20 +113,26 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
113113
}
114114

115115
func (m mainModel) View() string {
116+
header := lipgloss.NewStyle().Width(m.width).
117+
Border(lipgloss.NormalBorder(), false, false, true, false).
118+
BorderForeground(lipgloss.Color("8")).
119+
Foreground(lipgloss.Color("2")).
120+
Render("󰊢 diffnav")
121+
footer := m.footerView()
122+
116123
ft := ""
117124
ftWidth := m.getFileTreeWidth()
118125
if m.isShowingFileTree {
119126
ft = lipgloss.NewStyle().
120127
Width(constants.OpenFileTreeWidth).
121-
Height(m.height-footerHeight).
128+
Height(m.height-footerHeight-headerHeight).
122129
Border(lipgloss.NormalBorder(), false, true, false, false).
123130
BorderForeground(lipgloss.Color("8")).
124131
Render(m.fileTree.View())
125132
}
126-
dv := lipgloss.NewStyle().MaxHeight(m.height - footerHeight).Width(m.width - ftWidth).Render(m.diffViewer.View())
133+
dv := lipgloss.NewStyle().MaxHeight(m.height - footerHeight - headerHeight).Width(m.width - ftWidth).Render(m.diffViewer.View())
127134
content := lipgloss.JoinHorizontal(lipgloss.Top, ft, dv)
128-
footer := m.footerView()
129-
return lipgloss.JoinVertical(lipgloss.Left, content, footer)
135+
return lipgloss.JoinVertical(lipgloss.Left, header, content, footer)
130136
}
131137

132138
func (m mainModel) getFileTreeWidth() int {
@@ -194,7 +200,10 @@ func sortFiles(files []*gitdiff.File) {
194200
})
195201
}
196202

197-
const footerHeight = 1
203+
const (
204+
footerHeight = 1
205+
headerHeight = 2
206+
)
198207

199208
func (m mainModel) footerView() string {
200209
return lipgloss.NewStyle().

0 commit comments

Comments
 (0)