MCPcopy Create free account
hub / github.com/modem-dev/hunk / renderStaticFile

Function renderStaticFile

src/ui/staticDiffPager.ts:309–346  ·  view source on GitHub ↗

Format one parsed diff file for static pager hosts like LazyGit's diff panel.

(
  file: DiffFile,
  theme: AppTheme,
  options: CommonOptions,
  width: number,
)

Source from the content-addressed store, hash-verified

307
308/** Format one parsed diff file for static pager hosts like LazyGit's diff panel. */
309async function renderStaticFile(
310 file: DiffFile,
311 theme: AppTheme,
312 options: CommonOptions,
313 width: number,
314) {
315 const highlighted =
316 file.isBinary || file.isTooLarge ? null : await loadHighlightedDiff(file, theme);
317 const layout = resolveStaticLayout(options);
318 const rows =
319 layout === "split"
320 ? buildSplitRows(file, highlighted, theme)
321 : buildStackRows(file, highlighted, theme);
322 const lineNumberWidth = maxLineNumberWidth(file, rows);
323 const stats = `${colorText(`+${file.stats.additions}${file.statsTruncated ? "+" : ""}`, theme.badgeAdded)} ${colorText(`-${file.stats.deletions}`, theme.badgeRemoved)}`;
324 const status = colorText(`${fileStatusLabel(file)}${fileModeText(file)}`, theme.muted);
325 const header = `${colorText(fileDisplayPath(file), theme.text)} ${status} ${stats}`;
326
327 if (rows.length === 0) {
328 const message = file.isTooLarge
329 ? " Skipped because the file is too large to render."
330 : file.isBinary
331 ? " Binary file."
332 : " No textual changes.";
333 return [header, colorText(message, theme.muted)].join("\n");
334 }
335
336 return [
337 header,
338 ...rows
339 .map((row) =>
340 layout === "split"
341 ? renderStaticSplitRow(row, theme, lineNumberWidth, options, width)
342 : renderStaticStackRow(row, theme, lineNumberWidth, options),
343 )
344 .filter(Boolean),
345 ].join("\n");
346}
347
348function fallbackMessage(error: unknown) {
349 if (error instanceof Error && error.message) {

Callers 1

renderStaticDiffPagerFunction · 0.85

Calls 11

loadHighlightedDiffFunction · 0.90
buildSplitRowsFunction · 0.90
buildStackRowsFunction · 0.90
resolveStaticLayoutFunction · 0.85
maxLineNumberWidthFunction · 0.85
colorTextFunction · 0.85
fileStatusLabelFunction · 0.85
fileModeTextFunction · 0.85
fileDisplayPathFunction · 0.85
renderStaticSplitRowFunction · 0.85
renderStaticStackRowFunction · 0.85

Tested by

no test coverage detected