MCPcopy Create free account
hub / github.com/JanSmrcka/differ / renderCodeLine

Function renderCodeLine

internal/ui/diff.go:181–224  ·  view source on GitHub ↗
(dl DiffLine, filename string, styles Styles, t theme.Theme, width int)

Source from the content-addressed store, hash-verified

179}
180
181func renderCodeLine(dl DiffLine, filename string, styles Styles, t theme.Theme, width int) string {
182 oldNum := fmtLineNum(dl.OldNum)
183 newNum := fmtLineNum(dl.NewNum)
184
185 indicator := " "
186 var bgColor string
187 var numStyle lipgloss.Style
188 var indStyle lipgloss.Style
189 var bgStyle lipgloss.Style
190 switch dl.Type {
191 case LineAdded:
192 indicator = "+"
193 bgColor = t.AddedBg
194 numStyle = styles.DiffLineNumAdded
195 indStyle = styles.DiffAdded
196 bgStyle = styles.DiffAddedBg
197 case LineRemoved:
198 indicator = "-"
199 bgColor = t.RemovedBg
200 numStyle = styles.DiffLineNumRemoved
201 indStyle = styles.DiffRemoved
202 bgStyle = styles.DiffRemovedBg
203 default:
204 numStyle = styles.DiffLineNum
205 indStyle = styles.DiffContext
206 bgStyle = lipgloss.NewStyle()
207 }
208
209 nums := numStyle.Render(oldNum + " " + newNum)
210
211 // Syntax highlight the content
212 highlighted := highlightLine(dl.Content, filename, bgColor)
213
214 // Build: colored indicator + highlighted content + bg padding to fill width
215 codeWidth := width - lineNumWidth*2 - 3 // nums + spaces
216 prefix := indStyle.Render(indicator + " ")
217 contentWidth := lipgloss.Width(prefix) + lipgloss.Width(highlighted)
218 padding := ""
219 if pad := codeWidth - contentWidth; pad > 0 {
220 padding = bgStyle.Render(strings.Repeat(" ", pad))
221 }
222
223 return nums + " " + prefix + highlighted + padding
224}
225
226func fmtLineNum(n int) string {
227 if n < 0 {

Callers 1

renderDiffLineFunction · 0.85

Calls 2

fmtLineNumFunction · 0.85
highlightLineFunction · 0.85

Tested by

no test coverage detected