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

Function renderStaticDiffPager

src/ui/staticDiffPager.ts:376–410  ·  view source on GitHub ↗
(
  text: string,
  options: CommonOptions = {},
  deps: StaticDiffPagerDeps = { stderr: process.stderr },
)

Source from the content-addressed store, hash-verified

374
375/** Render diff-like pager stdin as colored static output, falling back to the original patch on failure. */
376export async function renderStaticDiffPager(
377 text: string,
378 options: CommonOptions = {},
379 deps: StaticDiffPagerDeps = { stderr: process.stderr },
380) {
381 try {
382 const bootstrap = await loadAppBootstrap({
383 kind: "patch",
384 file: "-",
385 text,
386 options: {
387 ...options,
388 pager: true,
389 },
390 });
391 const resolvedTheme = resolveTheme(options.theme, null, deps.customTheme);
392 const theme = options.transparentBackground
393 ? withTransparentSurfaces(resolvedTheme)
394 : resolvedTheme;
395 const width = resolveStaticWidth(deps);
396 const rendered = await Promise.all(
397 bootstrap.changeset.files.map((file) => renderStaticFile(file, theme, options, width)),
398 );
399
400 if (rendered.length === 0) {
401 warnFallback(deps, "no files rendered");
402 return sanitizeTerminalText(text);
403 }
404
405 return `${rendered.join("\n\n")}\n`;
406 } catch (error) {
407 warnFallback(deps, fallbackMessage(error));
408 return sanitizeTerminalText(text);
409 }
410}

Callers 2

mainFunction · 0.90

Calls 8

loadAppBootstrapFunction · 0.90
resolveThemeFunction · 0.90
withTransparentSurfacesFunction · 0.90
sanitizeTerminalTextFunction · 0.90
resolveStaticWidthFunction · 0.85
renderStaticFileFunction · 0.85
warnFallbackFunction · 0.85
fallbackMessageFunction · 0.85

Tested by

no test coverage detected