Files
playback/internal/ui/transcript/highlight.go
2026-01-25 17:13:15 -06:00

64 lines
1.5 KiB
Go

package transcript
import (
"fmt"
"time"
"github.com/charmbracelet/lipgloss"
"playback/internal/srt"
"playback/internal/ui"
)
// RenderCue renders a single cue with optional highlighting
func RenderCue(cue *srt.Cue, isCurrent, isSelected bool, width int) string {
// Format timestamp
timestamp := formatTimestamp(cue.Start, cue.End)
// Apply styles based on state
var textStyle, timestampStyle lipgloss.Style
if isSelected {
// Selected cue (navigation cursor) - use accent color
textStyle = ui.SelectedCueStyle
timestampStyle = ui.SelectedTimestampStyle
} else if isCurrent {
// Current cue (playback position)
textStyle = ui.CurrentCueStyle
timestampStyle = ui.TimestampStyle
} else {
textStyle = ui.BaseStyle
timestampStyle = ui.TimestampStyle
}
timestampStr := timestampStyle.Render(timestamp)
textStr := textStyle.Render(cue.Text)
// Add selection indicator
prefix := " "
if isSelected {
prefix = "> "
}
return fmt.Sprintf("%s%s\n%s%s\n", prefix, timestampStr, prefix, textStr)
}
// formatTimestamp formats start/end times as SRT timestamp
func formatTimestamp(start, end time.Duration) string {
return fmt.Sprintf("%s --> %s",
formatTime(start),
formatTime(end),
)
}
// formatTime formats a duration as HH:MM:SS,mmm
func formatTime(d time.Duration) string {
h := d / time.Hour
d -= h * time.Hour
m := d / time.Minute
d -= m * time.Minute
s := d / time.Second
d -= s * time.Second
ms := d / time.Millisecond
return fmt.Sprintf("%02d:%02d:%02d,%03d", h, m, s, ms)
}