▍ humdrum codex / glint v1.1.2
license AGPL-3.0
1.7 KB raw
 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
package app

import (
	"path/filepath"
	"strings"

	"glint/internal/theme"

	"github.com/charmbracelet/lipgloss"
)

// headerText is the name shown in the editor's filename bar: the file's
// basename without its extension, or "Untitled" for a buffer with no path. A
// frontmatter "title" deliberately does not override it — edit mode shows what
// is on disk. Unsaved changes append a bullet.
func (a *App) headerText() string {
	name := "Untitled"
	if a.path != "" {
		base := filepath.Base(a.path)
		name = strings.TrimSuffix(base, filepath.Ext(base))
	}
	if a.editor.Dirty {
		name += " •"
	}
	return name
}

// showHeader reports whether the filename bar belongs on screen: in the editor
// and the overlays that keep it visible beneath them. The picker has its own
// layout, help replaces the body, and preview draws its own title bar.
func (a *App) showHeader() bool {
	switch a.mode {
	case ModeEditor, ModeFind, ModeGotoLine, ModeSpell, ModeNamePrompt:
		return true
	}
	return false
}

// headerBar renders the filename as one content-column-wide row: a bold filled
// block in the heading color for a named file, muted plain text for an unnamed
// buffer so "unsaved and unnamed" reads at a glance. Returns "" when the header
// does not belong on screen.
func (a *App) headerBar() string {
	if !a.showHeader() {
		return ""
	}
	w := a.contentWidth()
	if w < 3 {
		return ""
	}
	label := truncate(" "+a.headerText()+" ", w)
	if a.path == "" {
		return lipgloss.NewStyle().
			Foreground(a.theme.Muted).
			Background(a.theme.Background).
			Width(w).
			Render(label)
	}
	return lipgloss.NewStyle().
		Bold(true).
		Foreground(lipgloss.Color(theme.LegibleText(string(a.theme.Heading)))).
		Background(a.theme.Heading).
		Width(w).
		Render(label)
}