58 lines
1.3 KiB
Go
58 lines
1.3 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, isActive bool, width int) string {
|
|
// Format timestamp
|
|
timestamp := formatTimestamp(cue.Start, cue.End)
|
|
|
|
// Apply styles based on state
|
|
var textStyle, timestampStyle lipgloss.Style
|
|
var prefix string
|
|
|
|
if isActive {
|
|
// Active cue (playback position + navigation cursor)
|
|
textStyle = ui.ActiveCueStyle
|
|
timestampStyle = ui.ActiveTimestampStyle
|
|
prefix = "> "
|
|
} else {
|
|
textStyle = ui.BaseStyle
|
|
timestampStyle = ui.TimestampStyle
|
|
prefix = " "
|
|
}
|
|
|
|
timestampStr := timestampStyle.Render(timestamp)
|
|
textStr := textStyle.Render(cue.Text)
|
|
|
|
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)
|
|
}
|