Skip to content

Commit e09c89b

Browse files
authored
Highlight the whole line not just the timestamp (#39)
1 parent b85790c commit e09c89b

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

internal/tui/components.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,8 @@ func (m *DashboardModel) renderLogScrollContent(height int, logWidth int) []stri
296296

297297
for i := startIdx; i < len(m.logEntries) && i < startIdx+maxLines; i++ {
298298
entry := m.logEntries[i]
299-
formatted := m.formatLogEntry(entry, logWidth)
300-
301-
// Highlight selected log when in log section or log viewer modal
302-
if (m.activeSection == SectionLogs || m.showLogViewerModal) && i == m.selectedLogIndex {
303-
selectedStyle := lipgloss.NewStyle().
304-
Background(ColorBlue).
305-
Foreground(ColorWhite)
306-
formatted = selectedStyle.Render(formatted)
307-
}
308-
299+
isSelected := (m.activeSection == SectionLogs || m.showLogViewerModal) && i == m.selectedLogIndex
300+
formatted := m.formatLogEntry(entry, logWidth, isSelected)
309301
logLines = append(logLines, formatted)
310302
}
311303

internal/tui/formatting.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,70 @@ import (
99
)
1010

1111
// formatLogEntry formats a log entry with colors
12-
func (m *DashboardModel) formatLogEntry(entry LogEntry, availableWidth int) string {
12+
func (m *DashboardModel) formatLogEntry(entry LogEntry, availableWidth int, isSelected bool) string {
1313
// Use receive time for display
1414
timestamp := entry.Timestamp.Format("15:04:05")
1515

16-
// Color severity levels
16+
// If selected, apply selection style to entire row
17+
if isSelected {
18+
// Format the entire row without individual component styling
19+
severity := fmt.Sprintf("%-5s", entry.Severity)
20+
21+
var logLine string
22+
if m.showColumns {
23+
// Extract host.name and service.name from OTLP attributes
24+
host := entry.Attributes["host.name"]
25+
service := entry.Attributes["service.name"]
26+
27+
// Truncate to fit column width
28+
if len(host) > 12 {
29+
host = host[:9] + "..."
30+
}
31+
if len(service) > 16 {
32+
service = service[:13] + "..."
33+
}
34+
35+
// Format fixed-width columns
36+
hostCol := fmt.Sprintf("%-12s", host)
37+
serviceCol := fmt.Sprintf("%-16s", service)
38+
39+
// Calculate remaining space for message
40+
// Use same calculation as non-selected: availableWidth - 18 - columnsWidth
41+
columnsWidth := 30 // 12 + 16 + 2 spaces
42+
maxMessageLen := availableWidth - 18 - columnsWidth
43+
if maxMessageLen < 10 {
44+
maxMessageLen = 10
45+
}
46+
47+
message := entry.Message
48+
if len(message) > maxMessageLen {
49+
message = message[:maxMessageLen-3] + "..."
50+
}
51+
52+
logLine = fmt.Sprintf("%s %-5s %s %s %s", timestamp, severity, hostCol, serviceCol, message)
53+
} else {
54+
// Calculate space for message - use same as non-selected: availableWidth - 18
55+
maxMessageLen := availableWidth - 18
56+
if maxMessageLen < 10 {
57+
maxMessageLen = 10
58+
}
59+
60+
message := entry.Message
61+
if len(message) > maxMessageLen {
62+
message = message[:maxMessageLen-3] + "..."
63+
}
64+
65+
logLine = fmt.Sprintf("%s %-5s %s", timestamp, severity, message)
66+
}
67+
68+
// Apply selection style to entire line
69+
selectedStyle := lipgloss.NewStyle().
70+
Background(ColorBlue).
71+
Foreground(ColorWhite)
72+
return selectedStyle.Render(logLine)
73+
}
74+
75+
// Normal (non-selected) formatting with individual component colors
1776
severityColor := ColorGray
1877
switch strings.ToUpper(entry.Severity) {
1978
case "FATAL", "CRITICAL":

0 commit comments

Comments
 (0)