xonecas.io
60255
Zn

Zoea-Nova / files

Zoea-Nova / internal / tui / styles.go

8.8 KB
1package tui
2
3import (
4	"fmt"
5	"strings"
6	"time"
7
8	"github.com/charmbracelet/lipgloss"
9)
10
11// Colors - Retro-futuristic aesthetic based on Zoea Nova brand
12// Brand colors from logo: #9D00FF (electric purple), #00FFCC (bright teal)
13var (
14	// Brand colors
15	colorBrand    = lipgloss.Color("#9D00FF") // Electric purple (from logo)
16	colorTeal     = lipgloss.Color("#00FFCC") // Bright teal (from logo)
17	colorBrandDim = lipgloss.Color("#6B00B3") // Dimmed purple for subtle accents
18	colorTealDim  = lipgloss.Color("#00AA99") // Dimmed teal
19
20	// Role colors (per design doc: user=green, assistant=magenta, system=cyan, tool=yellow)
21	colorUser      = lipgloss.Color("#00FF66") // Bright green for user messages
22	colorAssistant = lipgloss.Color("#FF00CC") // Magenta/pink for assistant (complements brand purple)
23	colorSystem    = lipgloss.Color("#00CCFF") // Cyan for system messages
24	colorTool      = lipgloss.Color("#FFCC00") // Yellow/gold for tool calls
25
26	// Semantic colors
27	colorError   = lipgloss.Color("#FF3366") // Error red-pink
28	colorSuccess = lipgloss.Color("#00FF66") // Success green
29	colorMuted   = lipgloss.Color("#5555AA") // Muted purple-gray
30
31	// Backgrounds - deep space with purple undertones
32	colorBg      = lipgloss.Color("#08080F") // Deep space black
33	colorBgAlt   = lipgloss.Color("#101018") // Slightly lighter
34	colorBgPanel = lipgloss.Color("#14141F") // Panel background
35	colorBorder  = lipgloss.Color("#2A2A55") // Purple-tinted border
36
37	// Legacy aliases for compatibility
38	colorPrimary   = colorBrand
39	colorSecondary = colorTeal
40)
41
42// Styles - Retro-futuristic command center aesthetic
43var (
44	// Base styles
45	baseStyle = lipgloss.NewStyle().
46			Background(colorBg)
47
48	// Header - Bold brand presence, no border (decorative lines in content)
49	headerStyle = lipgloss.NewStyle().
50			Bold(true).
51			Foreground(colorBrand).
52			Background(colorBgAlt)
53
54	titleStyle = lipgloss.NewStyle().
55			Bold(true).
56			Foreground(colorBrand)
57
58	// Mysis list - double border for that 80s terminal aesthetic
59	mysisListStyle = lipgloss.NewStyle().
60			Border(lipgloss.DoubleBorder()).
61			BorderForeground(colorBrandDim) // Was: colorBorder (#2A2A55, contrast 1.48:1)
62		// Now: colorBrandDim (#6B00B3, contrast ~3.0:1)
63
64	mysisItemStyle = lipgloss.NewStyle().
65			Foreground(colorTeal).
66			Padding(0, 1)
67
68	mysisItemSelectedStyle = lipgloss.NewStyle().
69				Foreground(colorTeal).
70				Bold(true).
71				Padding(0, 1)
72
73	// Mysis states - distinct colors for each state
74	stateRunningStyle = lipgloss.NewStyle().
75				Foreground(colorSuccess).
76				Bold(true)
77
78	stateIdleStyle = lipgloss.NewStyle().
79			Foreground(colorTeal)
80
81	stateStoppedStyle = lipgloss.NewStyle().
82				Foreground(colorMuted)
83
84	stateErroredStyle = lipgloss.NewStyle().
85				Foreground(colorError).
86				Bold(true)
87
88	// Logs/Messages - conversation styling per design doc
89	// No padding here - padding is added to content lines directly
90	// No border around viewport - clean look
91	logStyle = lipgloss.NewStyle()
92
93	// Role colors per design doc: user=green, assistant=magenta, system=cyan, tool=yellow
94	logUserStyle = lipgloss.NewStyle().
95			Foreground(colorUser).
96			Bold(true)
97
98	logAssistantStyle = lipgloss.NewStyle().
99				Foreground(colorAssistant)
100
101	logSystemStyle = lipgloss.NewStyle().
102			Foreground(colorSystem).
103			Italic(true)
104
105	logToolStyle = lipgloss.NewStyle().
106			Foreground(colorTool).
107			Italic(true)
108
109	// Input - teal border, brand prompt
110	inputStyle = lipgloss.NewStyle().
111			Border(lipgloss.RoundedBorder()).
112			BorderForeground(colorTeal).
113			Padding(0, 1)
114
115	inputPromptStyle = lipgloss.NewStyle().
116				Foreground(colorBrand).
117				Bold(true)
118
119	// Help - double border for prominence, centered brand feel
120	helpStyle = lipgloss.NewStyle().
121			Border(lipgloss.DoubleBorder()).
122			BorderForeground(colorBrand).
123			Background(colorBgPanel).
124			Padding(1, 2).
125			Margin(1)
126
127	helpKeyStyle = lipgloss.NewStyle().
128			Foreground(colorTeal).
129			Bold(true)
130
131	helpDescStyle = lipgloss.NewStyle().
132			Foreground(colorMuted)
133
134	// Panels - consistent with mysis list
135	panelStyle = lipgloss.NewStyle().
136			Border(lipgloss.RoundedBorder()).
137			BorderForeground(colorBorder).
138			Background(colorBgPanel).
139			Padding(0, 1)
140
141	panelTitleStyle = lipgloss.NewStyle().
142			Foreground(colorTeal).
143			Bold(true)
144
145	// Info/Stats - brand colors for values
146	labelStyle = lipgloss.NewStyle().
147			Foreground(colorMuted)
148
149	valueStyle = lipgloss.NewStyle().
150			Foreground(colorBrand).
151			Bold(true)
152
153	// Dimmed/Disabled
154	dimmedStyle = lipgloss.NewStyle().
155			Foreground(colorMuted)
156
157	// Highlight style for important info
158	highlightStyle = lipgloss.NewStyle().
159			Foreground(colorTeal).
160			Bold(true)
161)
162
163// StateStyle returns the appropriate style for a mysis state.
164func StateStyle(state string) lipgloss.Style {
165	switch state {
166	case "running":
167		return stateRunningStyle
168	case "idle":
169		return stateIdleStyle
170	case "stopped":
171		return stateStoppedStyle
172	case "errored":
173		return stateErroredStyle
174	default:
175		return stateIdleStyle
176	}
177}
178
179// RoleStyle returns the appropriate style for a message role.
180func RoleStyle(role string) lipgloss.Style {
181	switch role {
182	case "user":
183		return logUserStyle
184	case "assistant":
185		return logAssistantStyle
186	case "system":
187		return logSystemStyle
188	case "tool":
189		return logToolStyle
190	default:
191		return logSystemStyle
192	}
193}
194
195// RoleColor returns the foreground color for a message role.
196func RoleColor(role string) lipgloss.Color {
197	switch role {
198	case "user":
199		return colorUser
200	case "assistant":
201		return colorAssistant
202	case "system":
203		return colorSystem
204	case "tool":
205		return colorTool
206	default:
207		return colorSystem
208	}
209}
210
211// renderSectionTitle renders a section title that spans the full width.
212func renderSectionTitle(title string, width int) string {
213	return renderSectionTitleWithSuffix(title, "", width)
214}
215
216// renderSectionTitleWithSuffix renders a section title with an optional suffix (like scroll indicator).
217func renderSectionTitleWithSuffix(title, suffix string, width int) string {
218	// If title is empty, render continuous dashes (for bottom borders)
219	if title == "" && suffix == "" {
220		// Format: ⬧────────────⬧ (continuous dashes, no gap)
221		dashCount := width - 4 // -4 for ⬧─ on each side
222		if dashCount < 0 {
223			dashCount = 0
224		}
225		line := "⬧─" + strings.Repeat("─", dashCount) + "─⬧"
226		return panelTitleStyle.Width(width).Render(line)
227	}
228
229	// Format: ⬧── TITLE ──⬧ [suffix] with dashes filling the remaining space
230	// Account for: 2 (⬧ markers) + 2 (─ adjacent to markers) + title + 2 (spaces around title) = 4
231	titleWithSpaces := " " + title + " "
232	titleDisplayWidth := lipgloss.Width(titleWithSpaces)
233	suffixDisplayWidth := lipgloss.Width(suffix)
234	// Total fixed chars: ⬧─ (2) on each side = 4
235	availableWidth := width - titleDisplayWidth - 4 - suffixDisplayWidth
236	if availableWidth < 2 {
237		availableWidth = 2
238	}
239	leftDashes := availableWidth / 2
240	rightDashes := availableWidth - leftDashes
241
242	line := "⬧─" + strings.Repeat("─", leftDashes) + titleWithSpaces + strings.Repeat("─", rightDashes) + "─⬧"
243	if suffix != "" {
244		line += suffix
245	}
246	return panelTitleStyle.Width(width).Render(line)
247}
248
249// truncateToWidth truncates a string to fit within maxWidth display columns.
250// Uses rune-aware iteration to avoid cutting multi-byte characters.
251func truncateToWidth(s string, maxWidth int) string {
252	if maxWidth <= 0 {
253		return ""
254	}
255	currentWidth := 0
256	for i, r := range s {
257		charWidth := lipgloss.Width(string(r))
258		if currentWidth+charWidth > maxWidth {
259			return s[:i]
260		}
261		currentWidth += charWidth
262	}
263	return s
264}
265
266func formatSenderLabel(senderID, senderName string) string {
267	const maxLabelWidth = 12
268	if senderName != "" {
269		return truncateWithEllipsis(senderName, maxLabelWidth)
270	}
271	if senderID == "" {
272		return ""
273	}
274	prefix := "id:"
275	maxIDWidth := maxLabelWidth - lipgloss.Width(prefix)
276	if maxIDWidth <= 0 {
277		return prefix
278	}
279	return prefix + truncateWithEllipsis(senderID, maxIDWidth)
280}
281
282func truncateWithEllipsis(s string, maxWidth int) string {
283	if maxWidth <= 0 {
284		return ""
285	}
286	if lipgloss.Width(s) <= maxWidth {
287		return s
288	}
289	if maxWidth <= 3 {
290		return truncateToWidth(s, maxWidth)
291	}
292	return truncateToWidth(s, maxWidth-3) + "..."
293}
294
295// formatTickTimestamp formats a tick number and timestamp as "T#### ⬡ [HH:MM]" with colors.
296// The timestamp is converted to local time.
297// Colors: tick (teal), hexagon (brand purple), brackets+time (dimmed)
298func formatTickTimestamp(tick int64, ts time.Time) string {
299	timeStr := ts.Local().Format("15:04")
300
301	// Style components
302	tickStyle := lipgloss.NewStyle().Foreground(colorSecondary) // Teal
303	hexStyle := lipgloss.NewStyle().Foreground(colorBrand)      // Brand purple
304	timeStyle := lipgloss.NewStyle().Foreground(colorMuted)     // Dimmed
305
306	tickPart := tickStyle.Render(fmt.Sprintf("T%d", tick))
307	hexPart := hexStyle.Render("⬡")
308	timePart := timeStyle.Render(fmt.Sprintf("[%s]", timeStr))
309
310	return tickPart + " " + hexPart + " " + timePart
311}