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

Function RenderNewFile

internal/ui/diff.go:234–254  ·  view source on GitHub ↗

RenderNewFile renders file content as an all-added diff (for untracked files).

(content, filename string, styles Styles, t theme.Theme, width int)

Source from the content-addressed store, hash-verified

232
233// RenderNewFile renders file content as an all-added diff (for untracked files).
234func RenderNewFile(content, filename string, styles Styles, t theme.Theme, width int) string {
235 initChromaStyle(t.ChromaStyle)
236
237 var b strings.Builder
238 codeWidth := width - lineNumWidth*2 - 3
239
240 for i, line := range strings.Split(content, "\n") {
241 num := i + 1
242 nums := styles.DiffLineNumAdded.Render(" " + fmt.Sprintf("%4d", num))
243 highlighted := highlightLine(line, filename, t.AddedBg)
244 prefix := styles.DiffAdded.Render("+ ")
245 contentWidth := lipgloss.Width(prefix) + lipgloss.Width(highlighted)
246 padding := ""
247 if pad := codeWidth - contentWidth; pad > 0 {
248 padding = styles.DiffAddedBg.Render(strings.Repeat(" ", pad))
249 }
250 b.WriteString(nums + " " + prefix + highlighted + padding)
251 b.WriteByte('\n')
252 }
253 return b.String()
254}
255
256// RenderBinaryFile renders a placeholder for binary files.
257func RenderBinaryFile(styles Styles, width int) string {

Callers 2

loadDiffCmdMethod · 0.85
TestRenderNewFile_BasicFunction · 0.85

Calls 2

initChromaStyleFunction · 0.85
highlightLineFunction · 0.85

Tested by 1

TestRenderNewFile_BasicFunction · 0.68