xonecas.io
62159
Sy

symb / files

symb / internal / tui / view_status.go

2.2 KB
1package tui
2
3import (
4	"strconv"
5	"strings"
6
7	"charm.land/lipgloss/v2"
8)
9
10// renderStatusBar writes the status separator and bar.
11func (m Model) renderStatusBar(b *strings.Builder, bgFill lipgloss.Style) {
12	b.WriteString(m.styles.Border.Render(strings.Repeat("─", m.width)))
13	b.WriteByte('\n')
14
15	// -- Left segments --
16	var leftParts []string
17
18	// Git branch + dirty
19	if m.gitBranch != "" {
20		branch := m.gitBranch
21		if m.gitDirty {
22			branch += "*"
23		}
24		branchPart := m.styles.StatusText.Render(" " + branch)
25		if m.gitAdded+m.gitModified+m.gitRemoved > 0 {
26			counts := strings.Join([]string{
27				m.styles.StatusAdd.Render("+" + strconv.Itoa(m.gitAdded)),
28				m.styles.StatusMod.Render("~" + strconv.Itoa(m.gitModified)),
29				m.styles.StatusDel.Render("-" + strconv.Itoa(m.gitRemoved)),
30			}, m.styles.StatusText.Render(" "))
31			branchPart = strings.Join([]string{branchPart, counts}, m.styles.StatusText.Render(" "))
32		}
33		leftParts = append(leftParts, branchPart)
34	}
35
36	left := strings.Join(leftParts, m.styles.StatusText.Render("  "))
37
38	// -- Right segments --
39	var rightParts []string
40
41	// Network error (truncated)
42	if m.lastNetError != "" {
43		errText := m.lastNetError
44		if len(errText) > 30 {
45			errText = errText[:30] + "…"
46		}
47		rightParts = append(rightParts, m.styles.Error.Render("✗ "+errText))
48	}
49
50	// Provider config name + model
51	providerLabel := m.providerConfigName
52	if m.currentModelName != "" {
53		providerLabel += "/" + m.currentModelName
54	}
55	rightParts = append(rightParts, m.styles.StatusText.Render(providerLabel))
56
57	// Animated braille spinner — red on error, accent otherwise
58	frame := brailleFrames[m.spinFrame%len(brailleFrames)]
59	if m.lastNetError != "" {
60		frame = m.styles.Error.Render(frame)
61	} else {
62		frame = lipgloss.NewStyle().Background(ColorBg).Foreground(ColorHighlight).Render(frame)
63	}
64	rightParts = append(rightParts, frame)
65
66	right := strings.Join(rightParts, m.styles.StatusText.Render(" "))
67
68	// -- Compose: left + gap + right + trailing space --
69	leftW := lipgloss.Width(left)
70	rightW := lipgloss.Width(right)
71	gap := m.width - leftW - rightW - 1
72	if gap < 0 {
73		gap = 0
74	}
75	b.WriteString(left)
76	b.WriteString(bgFill.Render(strings.Repeat(" ", gap)))
77	b.WriteString(right)
78	b.WriteString(bgFill.Render(" "))
79}