Format one parsed diff file for static pager hosts like LazyGit's diff panel.
( file: DiffFile, theme: AppTheme, options: CommonOptions, width: number, )
| 307 | |
| 308 | /** Format one parsed diff file for static pager hosts like LazyGit's diff panel. */ |
| 309 | async 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 | |
| 348 | function fallbackMessage(error: unknown) { |
| 349 | if (error instanceof Error && error.message) { |
no test coverage detected