package editor import ( "strings" "github.com/charmbracelet/lipgloss" ) // Span is a run of text with a single Lipgloss style. type Span struct { Text string Style lipgloss.Style } // renderSpans concatenates styled spans into a single string. func renderSpans(spans []Span) string { var b strings.Builder for _, s := range spans { b.WriteString(s.Style.Render(s.Text)) } return b.String() } // renderSpansCursor renders spans rune-by-rune, drawing the cursor cell at the // given rune column with cursorStyle. A cursor at or past the end of the line // is drawn as a styled space. func renderSpansCursor(spans []Span, col int, cursorStyle lipgloss.Style) string { var b strings.Builder idx := 0 for _, s := range spans { for _, r := range s.Text { if idx == col { b.WriteString(cursorStyle.Render(string(r))) } else { b.WriteString(s.Style.Render(string(r))) } idx++ } } if col >= idx { b.WriteString(cursorStyle.Render(" ")) } return b.String() }