-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.go
More file actions
136 lines (111 loc) · 3.75 KB
/
header.go
File metadata and controls
136 lines (111 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"fmt"
"strings"
"github.com/charmbracelet/lipgloss"
)
// renderHeader produces a 2-line animated header, full terminal width.
func (m model) renderHeader() string {
// Align with panel content: 1 char centering margin + 1 char border = 2
indent := " "
rightPad := " "
logo := logoBadge.Render("Git Owl")
// Spinner
spin := spinnerStyle.Render(m.spinner.view())
branch := branchStyle.Render("⏵ " + m.branch)
// Dirty indicator + file count
fileCount := len(m.list.Items())
var dirty string
if fileCount > 0 && !m.allFiles {
dirty = dirtyIndicatorStyle.Render("●")
} else {
dirty = cleanIndicatorStyle.Render("✓")
}
count := fileCountStyle.Render(fmt.Sprintf("%d files", fileCount))
// ── Line 1: logo ... badges + owl top ──
line1Left := indent + logo
// Build right side: badges first, then owl (so owl is always flush-right)
var line1RightParts []string
if m.diffMode {
line1RightParts = append(line1RightParts, diffBadgeStyle.Render("DIFF"))
}
if m.treeMode {
line1RightParts = append(line1RightParts, treeBadgeStyle.Render("TREE"))
} else if m.allFiles {
line1RightParts = append(line1RightParts, allBadgeStyle.Render("ALL"))
}
line1RightParts = append(line1RightParts, owlStyle.Render(owlTop()))
line1Right := strings.Join(line1RightParts, " ")
if line1Right != "" {
line1Right += rightPad
}
gap1 := m.width - lipgloss.Width(line1Left) - lipgloss.Width(line1Right)
if gap1 < 1 {
gap1 = 1
}
bar1 := line1Left + strings.Repeat(" ", gap1) + line1Right
// ── Line 2: spinner + branch + files ... owl bottom ──
line2Left := indent + spin + " " + branch + " " + dirty + " " + count
if m.treeMode && m.treeCwd != nil && m.treeCwd.path != "" {
treePath := breadcrumbDirStyle.Render(" " + m.treeCwd.path + "/")
line2Left += treePath
}
line2Right := owlStyle.Render(m.owl.owlBottom()) + rightPad
gap2 := m.width - lipgloss.Width(line2Left) - lipgloss.Width(line2Right)
if gap2 < 1 {
gap2 = 1
}
bar2 := line2Left + strings.Repeat(" ", gap2) + line2Right
rendered1 := headerLine2Style.Width(m.width).Render(bar1)
rendered2 := headerLine2Style.Width(m.width).Render(bar2)
return rendered1 + "\n" + rendered2
}
// renderWithHelpOverlay renders the help overlay centered over the panel.
func (m model) renderWithHelpOverlay(header, panel, cmdbar string) string {
helpContent := m.renderHelpContent()
overlay := helpOverlayStyle.Render(helpContent)
panelHeight := lipgloss.Height(panel)
placed := lipgloss.Place(
m.width, panelHeight,
lipgloss.Center, lipgloss.Center,
overlay,
lipgloss.WithWhitespaceChars(" "),
)
return header + "\n" + placed + "\n" + cmdbar
}
// renderHelpContent produces the help text.
func (m model) renderHelpContent() string {
title := headerAccentStyle.Render("Keybindings")
type binding struct{ key, desc string }
renderSection := func(label string, bindings []binding) string {
header := helpSectionStyle.Render(label)
var lines []string
for _, b := range bindings {
key := cmdKeyStyle.Render(fmt.Sprintf("%9s", b.key))
desc := headerDimStyle.Render(" " + b.desc)
lines = append(lines, " "+key+desc)
}
return header + "\n" + strings.Join(lines, "\n")
}
nav := renderSection("Navigation", []binding{
{"enter", "Open file"},
{"esc", "Back"},
{"j/k/↑/↓", "Move cursor"},
{"Shift-↑/↓", "Half-page jump"},
{"g/G", "Top / bottom"},
{"h/l/←/→", "Pan left / right"},
})
views := renderSection("Views", []binding{
{"d", "Diff mode"},
{"p", "Markdown preview"},
{"t", "Tree view / all files"},
{"/", "Filter"},
{"r", "Refresh"},
})
actions := renderSection("Actions", []binding{
{"e", "Quick fix line"},
{"?", "This help"},
{"q", "Quit"},
})
return title + "\n\n" + nav + "\n\n" + views + "\n\n" + actions
}